edited by
21,985 views
49 49 votes

The recurrence relation capturing the optimal execution time of the $Towers \ of \ Hanoi$ problem with $n$ discs is

  1. $T(n) =  2T(n − 2) + 2$
  2. $T (n) =  2T(n − 1) + n$
  3. $T (n) =  2T(n/2) + 1$
  4. $T (n) =  2T(n − 1) + 1$

4 Answers

Best answer
53 53 votes

Recurrence relation for Towers of Hanoi is

$T(1) = 1$

$T(n) = 2 T( n-1 ) +1$

So Answer should be (D)

edited by
12 12 votes

Ref: https://www.hackerearth.com/blog/developers/tower-hanoi-recursion-game-algorithm-explained/

For a given $N $ number of disks, the way to accomplish the task in a minimum number of steps is:

  1. Move the top $N−1$ disks to an intermediate tower. (Look at the first $3$ steps in the figure) 
  2. Move the bottom disk to the destination tower.(Look at the $4^{th}$ step in the figure)
  3. Finally, move the $N−1$ disks from the intermediate peg to the destination tower.(Look at the last $3$ steps in the figure)

TOH (N=3,L,M,R)
{
  if(N==0)
    return;
  else {    
      TOH(N-1,L,R,M)
      MOVE(L-R)
      TOH(N-1,M,L,R)}
}

$T(N)=2T(N-1)+1$

edited by
0 0 votes

Following are the steps to follow to solve Tower of Hanoi problem recursively.

Let the three pegs be A, B and C. The goal is to move n pegs from A to C.
To move n discs from peg A to peg C:
    move n-1 discs from A to B. This leaves disc n alone on peg A
    move disc n from A to C
    move n?1 discs from B to C so they sit on disc n

The recurrence function T(n) for time complexity of the above recursive solution can be written as following.

T(n) = 2T(n-1) + 1, Hence D is the right answer.

0 0 votes
T(n) = 2T(n - 1) +1

Using Master's Method,

Since a = 2 and a > 1,

Therefore, T(n) = 2^(n/1) ..... [where b = 1 and for a > 1, T(n) = Θ(a^(n/b))]

Therefore, T(n) = Θ(2^n), which is the time complexity of Tower of Hanoi.
 

And Correct Option is D) T(n) = 2T(n - 1) +1
Answer:
Position:
Show:

Related questions

61 61 votes
5 answers 5 answers
23.8k
23.8k views
gatecse asked Aug 5, 2014
23,805 views
Let $W(n) $ and $A(n)$ denote respectively, the worst case and average case running time of an algorithm executed on an input of size $n$. Which of the following is ALWA...
15 15 votes
4 answers 4 answers
4.8k
4.8k views
gatecse asked Sep 29, 2014
4,848 views
Given the sequence of terms, $\text{AD CG FK JP}$, the next term is$\text{OV}$$\text{OW}$$\text{PV}$$\text{PW}$
17 17 votes
2 answers 2 answers
5.3k
5.3k views
gatecse asked Sep 29, 2014
5,320 views
Which one of the following options is the closest in meaning to the word given below?Mitigate DiminishDivulgeDedicateDenote
17 17 votes
2 answers 2 answers
5.1k
5.1k views
gatecse asked Sep 29, 2014
5,135 views
Choose the most appropriate alternative from the options given below to complete the following sentence:Despite several _________ the mission succeeded in its attempt to ...