We've seen mergesort before. Basic example for divide and conquer
divide the input into two pieces of equal size and solve the two subprobles with recursion.
5.1 - For some constant c, T(n) ⇐ to 2T(n/2) + cn when n > 2 and T(2) ⇐ c
Approaches to solving recurrences
Unrolling the mergesort solution
Subsituting into the mergesort recurrence - guess and check
An approach using partial substitution
5.3 T(n) ⇐ qT(n/2) + cn, when n > 2 and t(2) ⇐ c. q is not the number subproblems
What to do with q>2 subproblems
analyze the first few levels.
identify a patterns. at abitrary level j we have qq^j distinct instances each of size (n/2^j)
See diagram on page 216
sum over all levels of recursion.
end up with O(n^(log2(q))) (because of geometric series etc. (5.4)
can also apply partial substitution - to derive the answer above. (I like unrolling, but see page 217 if need review)
What happens when q = 1
well you keep solving half a problem so the work per level is decreasing
only one instance at each level
when we sum over we get linear order. (5.5)
Related recurrence
looking at a recurrence relation of T(n) ⇐ 2T(n/2) + O(n^2)
same process for Unrolling the recurssion. Can analyze, identify and sum.