본문 바로가기
Algorithms, data structure/개념

Big O Notation

by CodeMia 2022. 4. 10.

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) = n )

f(n) could be quadratic ( f(n) = n^2 )

f(n) could be liner ( f(n) = 1 )

f(n) could be something entirely different 

 

 

 

 

solution 2번

O(1)

 

 

 

solution 1번 

 

5n + 2 --> n 

Number of operations is (eventually) bounded by a multiple of n

O(n) 

 

 

 

 

countUpAndDown(n) 함수 

 

 

O(2n)이지만 O(n)과 같다. 

 

 

 

 

Nested loops 함수 

O(n * n) 

 

 

 

'Algorithms, data structure > 개념' 카테고리의 다른 글

Big O Time quiz  (0) 2022.04.10
Simplifying Big O Expressions  (0) 2022.04.10
[Big O] Timing our code  (0) 2022.04.09
Intro to Big O Notation  (0) 2022.04.09
브라우저 콘솔 스닙핏 여는 법 | opt+cmd+J (맥)  (0) 2022.04.09

댓글