Problem Detail: This is a practice problem I’ve come up with in order to study for an exam I have in a couple of hours. Again, here’s the problem: Show T(n) = 2T(n-1) + k is O(2^n) where k is some positive constant. First of all, 2^n is indeed the upperbound, right? Since I’ve made this problem up myself, I’m not 100% sure, but from what I have seen, this should be O(2^n). If so, here’s my progress: We want to show P(n) is true for all n > n0, where P(n) is the statement “T(n) <= c * 2^n” (for some fixed c, to be determined) For now, let’s fix c at T(1). Base case: n = 1 We want to show T(1) <= c * 2. Since c = T(1), our equation becomes T(1) <= T(1) * 2, which is trivially true. Inductive step: Assume P(n – 1) is true for n > 1. We want to show that P(n) holds.
T(n) = 2 T(n - 1) + k, by definition >= 2 (c * 2^(n-1) ) + k = c * 2^n + k
Here’s where I get stuck. How can we possibly show that c * 2^n + k <= c * 2^n for any value of c? Did I make a mistake somewhere?
Asked By : Trent Bing
Answered By : D.W.
You are right. We can’t show that $c times 2^n + k le c times 2^n$. It doesn’t matter how you choose $c$; you are doomed. So, this approach is a failure. You will need to find a different way to prove it. This sometimes happens. Don’t get discouraged. Often you’ll need to try a couple different proof strategies before you find one that works. Back to the drawing board! Here is what I suggest. To simplify your life, first pick a particular value of $k$: say, $k=1$, so your recurrence is $T(n) = 2 T(n-1) + 1$. Now, try writing out a table of the first 10 values of the recurrence, i.e., $T(1), $T(2), $T(3), ldots$ Does that give you any clues or ideas about what you can say about $T(n)$? Do you spot a pattern? This is a common strategy: look at small examples to see if you can spot a pattern, hypothesize a relationship (e.g., your closed form), then formally prove the relationship using proof by induction. If you read in a textbook, they might only show you the last step (the proof by induction) with no hint of where they got the relationship from in the first place, but now that you’re doing it yourself, you get to learn how to do it for real. Once you’ve proved by induction that $T(n)=…$ (your expression), it is easy to prove in one step that this is $O(2^n)$. This is also an instance of a common pattern when using proof by induction. The hardest step in proof by induction is figuring out what to prove: figuring out what the inductive predicate is. In your case, instead of trying to prove $T(n) le 2^n$, you will fare better by proving something more specific: proving that $T(n) = 2^{n-1} T(1) + (2^{n-1}-1)k$. This is sometimes known under the name “strengthening the invariant”. Here the invariant that we are trying to prove is $T(n) = 2^{n-1} T(1) + (2^{n-1}-1)k$. This is a “stronger” statement than $T(n) le 2^n$ (it is more specific, it gives us more information, it narrows down the possible values of $T(n)$ further). Counter-intuitively, in this case, proving something more specific actually turns out to be easy. Sometimes induction is surprising!
Best Answer from StackOverflow
Question Source : http://cs.stackexchange.com/questions/18900