Question: 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

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Chemical Engineering Questions!