Modify the Towers of Hanoi program to help identify its algorithm efficiency. Declare a static variable named

Question:

Modify the Towers of Hanoi program to help identify its algorithm efficiency. Declare a static variable named moveCount that keeps track of the total number of moves. Remove (or comment out) all the print statements that document a move, and replace them with statements that increment the moveCount variable. In the main method, prompt the user for the number of disks and assign the user input to a local variable named disks. Next, call the move method, but pass disks as an argument instead of the original program’s hardcoded 4 argument. After main calls the move method, add a statement that prints the value of disks and the final value of moveCount. Compare those output values with the values in Table 11.1 and identify the Big O growth rate for the Towers of Hanoi problem.

Table 11.1

n 4 16 64 256 1,024 0(1) 1 1 1 1 1 O(log n) 2 4 6 8 10 O(n) 4 16 64 256 1,024 O(n log n) 8 64 384 2,048

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: