Quick reference for three divide and conquer staples, with proof sketches.
Master Theorem
Given any recurrence of the form for all , we have:
- If , then
- If , then
- If , then
Root Finding
Given a continuous function and two points such that , there exists a root of in the interval by the intermediate value theorem. Since said root may be irrational, we aim to approximate it with an arbitrary precision .
- Algorithm: , assuming the orientation (flip the comparison otherwise)
- If , is a suitable approximation
- Otherwise, calculate the midpoint
- If then return
- else return
- Time:
- Proof:
- For any such that , if , then we find an approx to a root using queries to .
- : Output , since the whole interval is at most . This requires calls to .
- Suppose and consider an arbitrary , s.t. .
- If , output .
- If , solve on the interval . By I.H. this takes at most queries of .
- Otherwise, we have , since and . Solve the interval .
- In any case, we used at most queries to .
kth Smallest Element
- Algorithm:
- Select an approximate median element using the median of the medians of subarrays of size
- Partition each element into three sets,
- If , recurse on
- Else, if , return
- Else, recurse on