Design, Analysis, Implementation Flashcards
Big-O notation
Given two functions T(n) and f(n), that always return positive numbers,
T(n) ∈ O( f(n) )
if and only if there exist constants
c, n₀ > 0
such that,
for all n≥n₀,
T(n)≤cf(n)
5 Big-O Simplification Rules
- Constant multiple rule
- Domination rule
- Addition rule
- Multiplication rule
- Transitivity rule
Constant multiple rule
If T(n) ∈ O( f(n) )
and c>0,
then
T(n) ∈ O( c ∗ g(n) )
Domination rule
If T(n) ∈ O( f(n)+g(n) )
and
f(n) ∈ O( g(n) )
then
T(n) ∈ O( g(n) )
We say that g “dominates” f
Addition rule
If
T₁(n) ∈ O( f(n) )
and
T₂(n) ∈ O( g(n) )
then
T₁(n) + T₂(n) ∈ O( f(n) + g(n) ).
Multiplication rule
If
T₁(n) ∈ O( f(n) )
and
T₂(n)∈O( g(n) )
then
T₁(n) ∗ T₂(n) ∈ O( f(n)∗g(n) )
Transitivity Rule
If
T(n) ∈ O( f(n) )
and
f(n) ∈ O( g(n) )
then
T(n) ∈ O( g(n) )
Loop invariant
A property which is preserved at every iteration through the loop.
3 Steps to showing a loop invariant
- Initialization: The invariant is true at the beginning of the first iteration.
- Maintenance. If the invariant is true at the beginning of one iteration, it’s also true at the beginning of the next iteration.
- Termination. After the loop exists, the invariant PLUS the loop termination condition tells us something useful.
Big-Ω
T(n) ∈ Ω( f(n) )
if and only if
f(n) ∈ O( T(n) )
Big-Θ
T₁(n) ∈ Θ( T₂(n) )
if and only if both
T₁(n) ∈ O( T₂(n) ) and T₂(n) ∈ O( T₁(n) ).