Prev: Invariants and Recursive Algorithms Next: Elementary Data Structures |
What Every CMPT 225 Student Should Know About Mathematical Induction
- by Brad Bart, Simon Fraser University | ||||||||||||||||||||||
Part 1: Overview of Induction
Part 2: How Induction Relates to Computer Science
|
Part 2: How Induction Relates to Computer Science
Running Time Analysis of Merge Sort Welcome keener, for a little bit of bonus math. Your objective? Given the recursive definition of T(n):
. . . show that T(n) = O(n log n), i.e., for constants c, n0, the inequality T(n) ≤ c⋅n log n holds for every n ≥ n0.
The first step is to rewrite the recurrence so that you're dealing with pure algebra, rather than the big-O, i.e., substitute O(n) ≤ an.
Second, note that the ceiling and floor operators are going to make life difficult for you. Certainly, when n is even, they have no effect, but when n is odd, they will add ± 1/2 to the result. This will mean two cases in the inductive step.
Assume T(n) ≤ c⋅n log n holds for every n < k, and prove T(k) ≤ c⋅k log k. Case 1: k is even
Case 2: k is odd
If you're still paying attention, you'll notice the symmetry with Case 1. Except for the first term, the two expressions are identical, and so if only you could show
you would be home. Unfortunately, this inequality is false, and you can prove it is false by using calculus, or perhaps even mathematical induction. But it turns out that the left hand side is not that much bigger than the right hand side, which means that you can utilize a portion of the ck log 2 term to reduce its value by just enough to satisfy the inequality. Back to the action:
So, no matter whether k is even or odd, T(k) ≤ c⋅k log k, whenever k ≥ 3 and c ≥ max(a / log 2, a / log(3/2)) = a / log(3/2). [You're almost there. There's one last detail to take care of.]
The inductive step operates as long as the two subcases, i.e., T(⎡k/2⎤) and T(⎣k/2⎦), satisfy the inequality in the Inductive Hypothesis. Sadly, when k = 3, one of these subcases is T(1), which never satisfies T(n) ≤ c⋅n log n, no matter how large you pick your c. The solution is to pick a larger k for the inductive step, say k ≥ 4. Finally, choose c so that it satisfies both T(2) ≤ c⋅2 log 2 and T(3) ≤ c⋅3 log 3. That is, c ≥ max(a / log(3/2), T(2) / (2 log 2), T(3) / (3 log 3)). □ | ||||||||||||||||||||||
Next: Elementary Data Structures |