Question
Copy and paste your graph below: Based on the data collected, find an expression T(n) to estimate the time (in seconds) it takes to calculate
Copy and paste your graph below:
Based on the data collected, find an expression T(n) to estimate the time (in seconds) it takes to calculate hanoi(n):
T(n)=
2. Use the expression you got in part (b) to estimate the number of years it takes to calculate T(n) and hanoi(n):
T(75)=
T(100)=
CODE FOR GRAPH
from datetime import datetime
def hanoi (n, origin, destination, intermedia):
if n
return 1
else:
a = hanoi (n - 1, origin, intermedia, destination)
b = hanoi (n - 1, intermedia, destination, origin)
return a + b + 1
def timeIt (n, origin, destination, intermedia):
start = datetime.now ()
result = hanoi (n, origin, destination, intermedia)
end = datetime.now ()
elapsed = (end - start).total_seconds ()
return (result, elapsed)
def test ():
done = False
i = 1
while not done:
result, elapsed = timeIt (i, 'left', 'right', 'middle')
print ('time = %11.6fs, hanoi (%2d) = %12d' % (elapsed, i,
result))
if elapsed > 3600.0:
done = True
i = i + 1
test ()
5. Download the file "csc220al.py" from Canvas and run the program. This program will run with either Python 2.x or 3.x It contains a nave implementation to calculate the numbers of the steps to solve the "Tower of Hanoi" problem and gives timing information. When you run the program, it should produce lines similar to the followings 0.000000s, hanoi ( 0.000000s, hanoi ( 0.000000s, hanoi ( 0.000000s, hanoi ( 0.000000s, hanoi( 0.000000s, hanoi ( 0.000000s, hanoi 0.000000s, hanoi( 0.001255s, hanoi( 0.001254s, hanoi time = time - time- time time- time time - 15 31 63 127 time - 255 time - 511 time - (10) 1023 Be patient, the program will take anywhere between 2 to 4 hours to complete. When the program is running, you should minimize any other activities on the computer so the running time data will not be disturbed. Once the program execution is finished, you can use the data to plot the times versus the values of n in a graph. If you use logarithm scale for the times, you will get a curve very close to a straight line (especially towards the timing data at the end). Now visually inspect your curve and discard some beginning data that is not so straight Your curve should now look like the following 5. Download the file "csc220al.py" from Canvas and run the program. This program will run with either Python 2.x or 3.x It contains a nave implementation to calculate the numbers of the steps to solve the "Tower of Hanoi" problem and gives timing information. When you run the program, it should produce lines similar to the followings 0.000000s, hanoi ( 0.000000s, hanoi ( 0.000000s, hanoi ( 0.000000s, hanoi ( 0.000000s, hanoi( 0.000000s, hanoi ( 0.000000s, hanoi 0.000000s, hanoi( 0.001255s, hanoi( 0.001254s, hanoi time = time - time- time time- time time - 15 31 63 127 time - 255 time - 511 time - (10) 1023 Be patient, the program will take anywhere between 2 to 4 hours to complete. When the program is running, you should minimize any other activities on the computer so the running time data will not be disturbed. Once the program execution is finished, you can use the data to plot the times versus the values of n in a graph. If you use logarithm scale for the times, you will get a curve very close to a straight line (especially towards the timing data at the end). Now visually inspect your curve and discard some beginning data that is not so straight Your curve should now look like the followingStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started