The Gateway to Computer Science Excellence
+27 votes
4k views

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$
in Algorithms by
edited by | 4k views
+26

There are three towers named as Left, Middle, Right.
Tower Left contains 3 discs in decreasing size from bottom to top.
We have to move these 3 discs from Left tower to Right tower using Middle tower.
step 1: Move 2 discs from Left tower to Middle tower using Right tower. $n-1$ discs
Step 2: Move the remaining disc from Left tower to Right tower. $1-movement$
Step 3: Move 2 discs from Middle tower to Right tower using Left tower. $n-1$ discs

Recurrence relation:
 $T(n) = T(n-1) + T(n-1) + 1$
 $T(n) = 2T(n-1) + 1$

0
this should be the best answer.👍

4 Answers

+31 votes
Best answer

Recurrence relation for Towers of Hanoi is

$T(1) = 1$

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

So Answer should be (D)

by
edited by
+1 vote

 

Hope this helps:)

by
+1 vote

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 4th 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$

by
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.

by
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,345 questions
60,470 answers
201,795 comments
95,272 users