Divide and Conquer
- Somehow divide problem into $X$ spots of $n$ items, each size $n/X$
- Solve $X$ such problems
- Solutions of each combined into entire problem
- $T(n) = T(n/d) +$ some cost
- Master theorem
Merge Sort
- Select pivot, divide
- Merge, can do linearly
- $T(n) = 2T(n) = O(N\log N)$
- Note that we can find the median in linear time:
- Pick randomly pivot X
- Divide into two sets bigger and smaller than X
- Note that now $X$ is in its correct position
- Remove the smaller set, going in the direction of the pivot
- Repeat with smaller array until found median
Deterministic median finding
$\Theta(n)$ time
(Idea median of medians)