in Algorithms retagged by
2,840 views
20 votes
20 votes

You are given ten rings numbered from $1$ to $10$, and three pegs labeled $A$, $B$, and $C$. Initially all the rings are on peg $A$, arranged from top to bottom in ascending order of their numbers. The goal is to move all the rings to peg $B$ in the minimum number of moves obeying the following constraints:

  1. In one move, only one ring can be moved.
  2. A ring can only be moved from the top of its peg to the top of a new peg.
  3. At no point can a ring be placed on top of another ring with a lower number.

How many moves are required?

  1. $501$
  2. $1023$
  3. $2011$
  4. $10079$
  5. None of the above.
in Algorithms retagged by
2.8k views

1 comment

Extra information

Its time complexity is O(2^n)

the recurrence relation is T(n) = 2 T(n-1) +1 , T(1) = 1
2
2

3 Answers

17 votes
17 votes
Best answer
I think its Tower of Hanoi problem.
Therefore, total number of function call $2^{n} -1 = 1023$.

 $\therefore$ Option $B$.
edited by

3 Comments

yes it is tower of hanoi problem problem
0
0
1023 will be total Moves but not function calls.In TOH recursive we will call for TOH(0) also and it will be a function call but not a move.

fxn calls will be 2047 i guess but moves are 1023.Every function call will not give a move.Some will return from base condition
6
6

By generalizing the problem with 3 rings, we can say that for 'n' rings :

Total function calls=2n+1-1

Total number of moves=2n-1  (better to draw the tree, then answer)

5
5
13 votes
13 votes

it is a tower of hanoi problem. we can see recurrence relation for moves.

number of moves:

$T(0) = 0$

$T(1) = 1$

$T(2) = 3$

$T(3) = 7$

$T(4) = 15$

.

.

.

$T(10) = T(9) +T(9) +1$

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

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

           $= (2^n)-1$

           $=1023$

 so B is ans

edited by

1 comment

This should be the best answer.
0
0
0 votes
0 votes
Answer:

Related questions