Given the recurrence relations Tn for TowerOfHanoi Find th
Given the recurrence relations (T(n) = ...) for TowerOfHanoi. Find the time complexity of the algorithm, TowerOfHanoi, by solving T(n) in part (a).
Solution
The problem is divided into 2 parts, and a print statement.
So, the recurrence relation is: T(n) = 2 T(n-1) + 1. if n >= 1.
= 0 if n = 0.
And solving the reccurence to calculate the complexity is:
T(n) = 2 T(n-1) + 1
= 2(2T(n-2) + 1) + 1 = 22 T(n-2) + 21 + 20
= 22(2 T(n-3) + 1) + 21 + 20 = 23 T(n-3) + 22 + 21 + 20
=
=
= 2n T(n-n) + 2n-1 + 2n-2 + ... + 22 + 21 + 20 = 2n-1 + 2n-2 + ... + 22 + 21 + 20 = 2n - 1.
Therefore, the number of steps required to solve the problem is: 2n - 1.
