The Oh Family Flashcards
What do the terms ‘best’, ‘average’ & ‘worst’ mean when it comes to run time?
best = the best runtime given the best situation
worst = the worst runtime given the absolute worst situation
average = the general runtime of a general situation
What is the definition of big-Oh?
f(n) is O(g(n)) if and only if there exists positive constants c and n0, such that:
f(n) <= c x g(n) for all n >= n0
What properties does big Oh have?
It is reflexive & transitive, but not symmetric
What is the multiplication rule for big Oh?
If f1(n) is O(g1(n)) & f2(n) is O(g(n)), then there exists positive constants c1, c2, n1, n2.
Let n0 = max(n1, n2), then multiplying gives f1(n) x f2(n) <= c1 x c2 x g1(n) x g2(n) for all n >= n0
What is the rule consisting of dropping smaller terms in big Oh?
If a function tends towards 0 as n tends towards infinity, then you can effectively ‘discard’ that function from the equation.
What are the two ‘rules’ for big Oh?
Drop lower-order terms e.g. n if there is an n^2 present
Drop constant terms i.e. numbers such as 5
What are the 7 important functions to know for Big Oh?
In order of smallest to biggest:
Constant (1)
Logarithmic (log n)
Linear (n)
N-log-N (n log n)
Quadratic (n^2)
Cubic (n^3)
Exponential (2^n)
What does it mean by ‘exponents vs powers’?
Exponentials grow faster than powers. To cancel out a power, use an exponential e.g. 2^n to cancel n^2
What does it mean by ‘powers vs logs’?
Powers grow faster than any power of a log. To cancel a log, you use any power, typically n^2, but whatever you have present will do
What are some big Oh conventions?
Use the smallest ‘reasonable’ possible class of functions
Use the simplest expression of the class
What are the other members of the big Oh family?
Big Oh (O)
little-oh (o)
Big-Omega (Omega)
Big-Theta (Theta)
What is the definition of big-Omega?
f(n) is Big-Omega(g(n)) if there are positive constants c and n0 such that:
f(n) >= c g(n) for all n >= n0
What are big-Omega’s properties?
Reflexive, Transitive, not symmetric
What is the definition of big-theta?
f(n) is Big-Theta(g(n)) if there are positive constants c, c’ and n0 such that:
f(n) <= c g(n)
f(n) >= c’ g(n)
for all n >= n0
What are the properties of Big-Theta?
Reflexive, transitive and symmetric