Wednesday, September 12, 2012

Big O Notation - Illustration


Big Oh notation is used in computer science to decribe the complexity of an algorithm in terms of time and space (memory). Big Oh notation describes the worst case scenario of what happens when an algorithm is run with N values and is really only useful when talking about large sets of data.

constantlogarithmiclinearquadraticcubic
nO(1)O(log N)O(N)O(N log N)O(N2)O(N3)
1111111
2112248
412481664
81382464512
161416642564,096
1,0241101,02410,2401,048,5761,073,741,824
1,048,5761201,048,57620,971,52010121016



Explanation:

O(1) = irrespective of changing the size of the input, time stays the same
O(N) = as you increase the size of input, the time taken to complete operations scales linearly with that size
O(log N) = growth curve that peaks at the beginning and slowly flattens out as the size of the data sets increase
O(N2) = growth will double with each additional element in the input

Some other links:
http://science.slc.edu/~jmarshall/courses/2002/spring/cs50/BigO/index.html


No comments:

Post a Comment