본문 바로가기

Algorithms, data structure/개념6

Big O Time quiz 다음 함수의 Big O는? function logAtLeast5(n){ for (var i = 1; i function logAtLeast5(n){ for (var i = 1; i (이해 안감) function onlyElementsAtEvenIndex(array){ var newArray = Array(Math.ceil(array.length / 2)); for (var i = 0; i function subtotals(array) { var subtotalArray = Array(array.length); for (var i = 0; i 2022. 4. 10.
Simplifying Big O Expressions 이 전 포스트에서 for loop 함수를 보면 2n 에서 5n + 2 까지의 operations 가지는데 이것은 간단히 --> n 과 같아진다. 몇 번의 n은 상관없이 트랜드를 보는 것이다. 이렇게 알고리즘의 Time complexity를 진단할 때 Big O expressions을 위해 몇 가지 법칙이 있다. 1. Constants runtime Don't Matter O(2n) --> O(n) O(500) --> O(1) O(13n^2) --> O(n^2) 2. Smaller Terms Don't Matter O(n + 10) --> O(n) O(1000000n + 50) --> O(n) O(n^2 + 5n + 8) --> O(n^2) Big O Shorthands 1. Arithmetic opera.. 2022. 4. 10.
Big O Notation Big O Notation a numeric representation of the performance of code. It allows us to talk formally about how the runtime of an algorithm grows as the inputs grow. We won't care about the details, only the trends Big O Definition an algorithm is O(f(n)) if the number of simple operations the computer has to do is eventually less than a constant times f(n), as n increases. f(n) could be liner ( f(n.. 2022. 4. 10.
[Big O] Timing our code 다음의 문제를 생각해 보자. Q: Suppose we want to write a function that calculates the sum of all numbers from 1 up to (and including) some number n. If you came up with these two solutions below, you're going to think about which one is better? solution 1 function addUpTo(n) { total = 0; for(let i=1; i 2022. 4. 9.
Intro to Big O Notation Big O a numeric representation of the performance of code. Why should we use Big O? Let say there is a problem having 10 different solutions. how performs compared to others? 1. we need to have a precise vocabulary to talk about how our code performs. 2. It's also good for discussing trade-offs between different approaches. because often it's not as cut and dried as I made it seem, it's not that.. 2022. 4. 9.
브라우저 콘솔 스닙핏 여는 법 | opt+cmd+J (맥) 스닙핏을 열어 알고리즘 연습을 할 것이다. 스닙핏 여는 법 1. inspect 가기 오른쪽 버튼 - inspect opt + cmd + j (맥) 2. sources tap 으로 가기 3. snippets옆 >> 이 모양 버튼 눌러 snippet을 선택한다. 4. 새 snippet을 만들고 이름을 바꿔준다. 5. console.log("Hello World") 쳐보기 2022. 4. 9.