please solve on httpsjsfiddlenet dont try to answer it if yo

please!!! solve on https://jsfiddle.net

don\'t try to answer it if you can\'t use https://jsfiddle.net

seperate the HTLM from the javascript

and also please show that the code runs

Tower of Hanoi

The classic example of a recursive solution to a relatively complex problem is the Tower of Hanoi https://en.wikipedia.org/wiki/Tower_of_Hanoi - which is taught in every Computer Science program and in a lot of programming classes. As you add disks the solution becomes more complex, but it is a simple repetition of moves used in the 3 disk solution.

Assignment

We are going to solve the classic Tower of Hanoi. Using the Wikipedia article I want you to write a computer program that calculates the number of moves necessary to solve Tower of Hanoi given a number of disks. There are formulas that calculate this - you are NOT going to use them. You will calculate this by implementing the recursive algorithm of the tower and counting every time a block is moved. You may also want to print out the moves. Also I recommend not allowing input greater that 7 blocks - it starts getting pretty big after that.

This can easily be implemented by using your Stack from previous assignments - all you really do in this is push and pop from the stack.

Answer the following questions in the interface of your code;

1. What is the Complexity (In Big O)?

2. Should we be concerned with concerned with the legend of the world ending when the 64 disk solution is physically solved it it takes 2 seconds for each move?

Solution

Open https://jsfiddle.net and paste the below code in the javascript section and run the code

function TowerOfHanoi(disk,s,a,d)
{
if (disk > 0)
  {
     TowerOfHanoi(disk - 1,s,d,a);
     document.write(\"Disk \" + disk + \" is moved from \" + s + \" to \" + d + \"<br />\");
    TowerOfHanoi(disk - 1,a,s,d);
    }
};

TowerOfHanoi(4,\"Source\",\"Auxiliary\",\"Destination\");

1) From the above solution we can see that

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

Lets take few exaples:

T(1) =1
T(2)=2T(1) + 1 =3
T(3)=TM(2) + 1 =7
T(4)=2T(3) + 1 =15

On looking the above scenarios we can figure out that
T(n) = 2^n - 1

Big O = O(2^n)

2) T(n) = 2^n - 1 = (2^64 - 1) moves

1 moves = 2 secs

Therefore (2^64 - 1) = (2^64 - 1) * 2 seconds --> 1000 billion years

In short we should not be concerned for such large value.

please!!! solve on https://jsfiddle.net don\'t try to answer it if you can\'t use https://jsfiddle.net seperate the HTLM from the javascript and also please sho
please!!! solve on https://jsfiddle.net don\'t try to answer it if you can\'t use https://jsfiddle.net seperate the HTLM from the javascript and also please sho

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site