Complexity Flashcards
What is the master method?
A method for finding the TIME COMPLEXITY of a RECURSIVE algorithm (Θ)
What form are the recurrences that we can solve with the master method?
T(N) = aT(n/b) + f(n)
a>=1 subproblems
b> 1 subsets of input
f(n)>0
What are the three cases in the master method?
1.f(n) = O (n^(logb(a)- e)), e>0
T(n) = Θ(n^(logb(a)))
2.f(n) = Θ(n^logb(a))
T(n) = Θ(n^(logb(a)) * logn)
3.f(n)= Ω(n^(logb(a)+e))
af(n/b) <= cf(n), c < 1
T(n ) = Θ(f(n))
What is the intuition behind the master method?
<= is O == is Θ >= is Ω -Compare f(n) to n^(logb(a)) largest is the solution
What is the worst case complexity of binary search? Why?
logn
It is the number of times you have to cut array in half to make it a single element.
Give a simple definition of Asymptotic Analysis.
Asymptotic: BEHAVIOUR of function when input gets LARGE. Analysis tries to PREDICT this.
Is O(f+g)εO(f)+O(g) true or false?
False
O(n^2+n) =n^2
O(n^2) + O(n) = n^2 + n
There’s no constant to make the first less than the second
Is O(fxg) = O(f)x O(g) True or False?
True
O(n^2 x n) = n^3
O(n^2)x O(n) = n^3
What does it mean for f to be Θ(g)?
There’s two constants c1,c2>0 and a No>=N s.t
f is always between c1g and c2g
Explain the worst time complexity of mergesort
nlogn. It takes logn splits to SPLIT array into n elements. Then it has to ACCESS each element, which take n time.
What do recurrences express?
The running TIME of RECURSIVE algorithms
What are the 3 methods we learned to solve recurrences?
- Master Theorem
- Substitution
- Iteration