20 likes | 103 Views
Computational Time Required to Solve the Tower of Hanoi.
E N D
Computational Time Required to Solve the Tower of Hanoi • To solve the Tower of Hanoi problem, a recursive approach was taken. To move n disk from one tower to another we first move (n-1) disk to an auxiliary tower, then move the bottom disk to its final destination, and then move the (n-1) disk to their final destination. • The time required for various operations was measure and any overhead not associated with the function was subtracted out. • 1E+9 Operations were performed on a Pentium(4) running at 2400.153 MHz. The times required for a single operation are as follows : • To call the function (w/o performing any operations): Tf = 5.171/1E+9 s • To move a single disk w/ necessary bookkeeping: T[1] = 14.157/1E+9 s • To compute auxiliary tower and pass over n=1 case: Taux = 2.742/1E+9 s
Computational Time Required to Solve the Tower of Hanoi • Now a recursive relationship can be written and solved for the time as a function of n • Let T[n] be the time required to solve problem for n disks then : T[n] = Tf + Taux + 2T[n-1] + T[1] = C + 2 T[n-1] (letting C= Tf + Taux + T[1] ) = C + 2 (C +2 T[n-2]) = C + 2 (C + 2 (C + 2 T[n-3]) = C + 2C + 2^2C + …+ 2^(k-1)C + 2^k T[n-k] (In general) = C (2^k – 1) + 2^k T[n – k] = C (2^(n-1) – 1) + 2^(n-1)*T[1] By n – 1 k • Substituting the times found earlier : T[64] = 2.036E+11 + 1.306E+11 = 3.342E+11 s or 10,590 years