Wednesday, 31 October 2012

Recurrence problem

When I read some books, i found solving Towers of Hanoi problem let me understand the whole process of proof.

Everyone knew Hanoi problem. So the recursive solution has three stages.
Stage1:  Move the top n-1 disks from the first post to the first post to the second using the solution for n -1 disks. This can be done in Tn-1 steps.
Stage2: Move the largest disk from the first top to the third post. This takes just 1 step.
Stage3: Move the n - 1 disks from the second post to the third post, again using the solution for n - 1 disk. This can also be done in Tn-1 steps.

This algorithm shows that Tn, the minimum number of steps required to move n disks to a different post, is at most Tn-1 + 1 + Tn-1 = 2Tn-1 + 1.

So we can find a recurrence.

T1 = 1
Tn = 2Tn-1 + 1  for n >= 2

So we can use this recurrence to compute any number of terms in the sequence:
T1 =1
T2 = 2T1 + 1 = 3
T3 = 2T2 + 1 = 7
T4 = 2T3 + 1 = 15
...

Let us prove this Claim

the proof is by induction on n. The induction hypothesis is that Tn = 2^n - 1. This is true for n = 1 because T1 = 1 = 2^1 -1.
Assume that Tn -1 = 2^(n-1) -1 in order to prove that Tn = 2^n -1. Where n >= 2
Tn = 2Tn-1 + 1 = 2(2^(n-1) - 1 ) + 1 = 2^n -1

The first equality is the recurrence equation, the second follows from the induction assumption, and the last step is simplification.

No comments:

Post a Comment