Divide-and-conquer Flashcards
What’s the recurrence relation and bigO time of the simple divide-and-conque for polynomial Multiplication
T(n) = 4T(n/2) + O(n)
T(n) = O(n2)
What’s the recurrence relation and bigO time of the Gauss’s trick for polynomial Multiplication
T(n) = 3T(n/2) + O(n)
T(n) = O(nlog23)
Master theorem. a/bd >1. What’s big O
O(nlogba)
Master theorem. a/bd <1. What’s big O
O(nd)
Master theorem. a/bd =1. What’s big O
O(ndlogn)
Binary search can only apply to sorted arrays?
Yes
What’s the recurrence of Binary search and what’s bigO time
T(n) = T(n/2)+O(1)
O(logn)
What’s the recurrence of Mergesort and what’s bigO time?
T(n) = 2T(n/2) + O(n)
O(nlogn)
Mergesort psedo-code
Is mergesort optimal?
Yes.
Consider any such tree that sorts an array of n elements. Each of its leaves is labeled by a permutation of {1, 2, … , n}. In fact, every permutation must appear as the label of a leaf. The reason is simple: if a particular permutation is missing, what happens if we feed the algorithm an input ordered according to this same permutation? And since there are n! permutations of n elements, it follows that the tree has at least n! leaves.
This is a binary tree, and we argued that it has at least n! leaves. Recall now that a binary tree of depth d has at most 2d leaves (proof: an easy induction on d). So, the depth of our tree–and the complexity of our algorithm–must be at least log(n!). And it is well known that log(n!) >= c*n*log n for some c > 0.
We have established that any comparison tree that sorts n elements must make, in the worst case, (n log n) comparisons, and hence mergesort is optimal!
expected average and worst time of finding medium with good pivot?
T(n) <= T(3n/4) + O(n)
average time: O(n)
Worst time: O(n2)
expected average and worst time of quicksort
average time O(n logn)
worst time O(n2)
pseudo-code for finding good pivot and medium
BigO time for simpy matrix multiplication
O(n3)
what’s the Inversion formula of FFT coefficient matrix Mn(w)-1?
Mn(w)-1 = 1/n*Mn(w-1)