recategorized by
776 views
2 votes
2 votes
We solve TOH problem recursively breaking the task in three sections, which of the following recurrence will accord well with the approach , that is shows correct order of work done on each recursive step

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

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

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

D) T(n)=T(n-1)+T(n-1)+2
recategorized by

3 Answers

2 votes
2 votes
Tower of Hanoi function works as:

TOH(n, x,y,z){

if(n>=1)

{

1.TOH(n, x,z,y) .//....(T(n-1))

2.move x->y  .//.....(1)

3.TOH(n,z,y,x)  //.....(T(n-1))

} }

thus TOH function is recursively called and step 2 is just move which takes O(1) time so as it is asked order of work, option 1 is correct.
1 votes
1 votes
As we know disks are to be arranged using 3 tower or peg.

All disks are on 1st peg in such a way that largest at the bottom and then decreasing in size towards top.

Aim is to move n disks from 1 to 3rd peg using the 2nd.

n-1 disks are moved to 2nd stand.

Then  the largest disk is moved to 3rd stand. (1 move)

Then recursively the n-1 disks are moved to the 3rd stand.

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

Related questions

2 votes
2 votes
1 answer
1
Naveen Kumar 3 asked Jul 18, 2018
1,221 views
a) Wednesdayb)Tuesdayc)Thursdayd)Fridaye)None of the above
1 votes
1 votes
1 answer
2
himanshu6398 asked Oct 9, 2018
432 views
While calculating the cost of growable array-based stack.... the cost of n pushes came out as a series - 2 + 4 + 8 + 16 +......+2^(logn + 1) and it equals to 4n - 1. I di...