Big O complexity Flashcards
What are the different levels of BigO complexity?
O(log n)
O(n)
O(n log n)
O(n2)
O(n3)
O(2^n)
What are the two approaches to time complexity?
Theoretical Analysis - study the number of times the algorithm performs some basic operations
Empirical Analysis - Code and run the algorithm on a computer for some inputs and measure how long it takes
How is time complexity calculated
Number of basic operations in terms of the input size.
Downsides of Empirical analysis
▶ Depends upon the speed of the computer
▶ A slow algorithm will waste time to test
▶ It is hard to reason about how the algorithm will perform for an arbitrary input (we can’t try all inputs!)
What is Worst Case efficiency?
T(n) is the maximum running time (in
terms of number of basic operations) for any input of size n.
Rank in terms of efficiency:
Exponential
Constant
Logarithmic
Polynomial
- Constant O(1)
- Logarithmic O(log n)
- Polynomial O(n, n2, n3)
- Exponential O(2^n)
State the formal definition of big-O notation, i.e.:
f (n) ∈ O(g(n)) if
There exists constants c > 0
and n0 > 0
such that f (n) ≤ c · g(n)
for all n > n0