|
|
|
|
|
by melonmouse
696 days ago
|
|
The linked proof for that median of medians is O(n) feels counterintuitive to me. Here's a (simpler?) alternative. T(0) = 0
T(1) = 1
T(n) = n + T(n/5) + T(7/10*n)
We want to prove that: T(n) ≤ C*n
It is intuitive that T(a+b) ≥ T(a) + T(b), or in other words, T is superadditive. That can be shown by induction:Induction base: it holds for all a+b < 1, the only case being a=0, b=0: T(0+0) = 0 + T(0) + T(0) ≥ T(0) + T(0)
Induction step: suppose it holds for all a+b < k. Let a+b = k. T(a+b) = T(k)
= k + T(k/5) + T(7/10*k)
≥ k + T(a/5) + T(b/5) + T(7/10*a) + T(7/10*b)
= [a + T(a/5) + T(7/10*a)] + [b + T(b/5) + T(7/10*b)]
= T(a) + T(b)
Because T is superadditive: T(n) = n + T(n/5) + T(7/10*n)
≤ n + T(n/5 + 7/10*n)
= n + T(9/10*n)
Now we can apply the master theorem. Or to write out the proof (using a geometric series): T(n) ≤ n + T(9/10*n)
≤ n * ∑ᵢ₌₀ᶦⁿᶠᶦⁿᶦᵗʸ (9/10)^i
= n * 1/(1-9/10)
= 10*n
So, we have shown the algorithm is O(n) with C=10 (or less). |
|
Here is the slightly mopped up proof i had in mind, when i posted my hints below: