Chapter3 - Counting 101 - Recursion and Recurrence(2)
Book - Python Algorithms by Magnus Lie Hetland
Chapter 3 - Counting 101
Guessing and Checking
Inductive Proof (κ·λ©μ μ¦λͺ )
Unraveling recurrence and finding a pattern is subject to unwarranted assumption. To be sure that a solution is correct, we should conjure up a solution by guess work or intuition and then show that itβs right.
For example, take \(T(n) = T(n-1) + 1\).
We want to check whether \(T(n)\) is \(O(n)\).
To find this, we try to verify that \(T(n) β€ cn\), for some an arbitrary \(c β₯ 1\).
We set \(T(1) = 1\). And itβs right.
How about large values for n?
This is where the induction comes in. The idea is quite simple: We start with \(T(1)\), where we know our solution is correct, and then we try to show that it also applies to \(T(2)\), \(T(3)\), and so forth.
By proving an induction step, showing that if our solution is correct for \(T(nβ1)\), it will also be true for \(T(n)\), for \(n > 1\). This step would let us go from \(T(1)\) to \(T(2)\), from \(T(2)\) to \(T(3)\), and so forth, just like we want.
\(T(nβ1) β€ c(nβ1)\) leads to \(T(n) β€ cn\), which (consequently) leads to \(T(n+1) β€ c(n+1)\), and so forth. Starting at our base case, \(T(1)\), we have now shown that \(T(n)\) is, in general, \(O(n)\).
Strong Induction
Letβs do recurrence 8 from [table 3-1]. Now, an induction hypothesis will be about all smaller numbers. More specifically, Iβll assume that \(T(k) β€ ck \log k\) for all positive integers \(k < n\) and show that this leads to \(T(n) β€ cn \log n\). In particular, we now hypothesize something about \(T(n/2)\) as well, not just \(T(nβ1)\).
[Table 3-1]
Leave a comment