Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Industrial Plastics Theory And Applications

Authors: Erik Lokensgard

6th Edition

1285061233, 978-1285061238

More Books

Students also viewed these Chemical Engineering questions

Question

Our deadline is 4/7, but we wont be ready before 4/11.

Answered: 1 week ago