Professional Documents
Culture Documents
Complexity Analysis: (For Reading)
Complexity Analysis: (For Reading)
Complexity Analysis: (For Reading)
(For reading)
Big O notation is also called Big Oh notation, Landau notation, Bachmann–Landau notation, and
asymptotic notation. A description of a function in terms of big O notation usually only provides an
upper bound on the growth rate of the function; associated with big O notation are several related
notations, using the symbols o, Ω, ω, and Θ, to describe other kinds of bounds on asymptotic growth
rates. Data Structures and Algorithms in Java 20/47
big-oh notation pronouncement :
O(1) : O to the one
O(n) : O to the n, Big-O of n
O(log2 n): O to the log2 n
constant O(1)
logarithmic O(logn)
linear O(n)
nlogn O(nlogn)
quadratic O(n2)
polynomial O(nb)
exponential O(bn)
factorial O(n!)
Data Structures and Algorithms in Java 31/47
Growth orders of functions in graphics
60
50
Small
problems - 40
n
we’re not Large4 log n
Time
interested! 30
problems
n -
20 we’re
4log2n interested
Binary search 10
in this gap!
More complex
Higher constant factor 0 0 10 20 30 40 50 60
Data Structures and Algorithms in Java 33/47
n
Determining time complexity
• Average case:
C(op1, op2, op3, . . .) = Cavg(op1) + Cavg(op2) + Cavg(op3) + . . .
• Amortized:
C(op1, op2, op3, . . .) = C(op1) + C(op2) + C(op3) + . . .