Answered step by step
Verified Expert Solution
Question
1 Approved Answer
3) Graph Plot: [2 marks] Append the following code segment after the implementations given in the previous problem. [Yes, The code is given. Just Copy-Paste
3) Graph Plot: [2 marks] Append the following code segment after the implementations given in the previous problem. [Yes, The code is given. Just Copy-Paste it). This will generate a graph with the value of n along the x-axis and time required along the y-axis. You can see both the curves in the same graph for better comparison. Generate graphs for different values of n and see how the performances change drastically for larger values of n. Code for plotting graph: import time import math import matplotlib.pyplot as plt import numpy as np #change the value of n for your own experimentation n = 30 x = [i for i in range(n)] y = [o for i in range(n)] z = [0 for i in range(n)] for i in range(n-1): start = time, time() fibonacci_1(x[i+1]) y[i+1)= time, time()-start start = time. time() fibonacci_2(x[i+1]) z[i+1)= time. time()-start x_interval = math.ceil(n/10) plt.plot(x, y, 'r') plt.plot(x, z, 'b') plt.xticks(np.arange(min(x), max(x)+1, x_interval)) plt.xlabel('n-th position') plt.ylabel('time') plt.title('Comparing Time Complexity!') plt.show()
Step 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