Created
January 2, 2018 19:58
-
-
Save pranavgarg/58744db65aed50f0dbe7f99217228ffa to your computer and use it in GitHub Desktop.
plot runtimes for different big oh notation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
import math | |
n = range(1,9) # input range | |
lgn = [math.log(x,2) for x in n] #logn | |
l = [x for x in n] # linear | |
nlgn = [x*math.log(x,2) for x in n] # nlogn | |
q = [x**2 for x in n] # quadratic | |
p = [2**i for i in n] # polynomial | |
plt.plot(n, lgn, label="logn") | |
plt.plot(n, l, label="linear") | |
plt.plot(n,nlgn, label="nlogn") | |
plt.plot(n,q, label="quadratic") | |
plt.plot(n,p, label='polynomial') | |
plt.legend(loc='upper left') | |
plt.xlabel('input range values (n)') | |
plt.ylabel('time range on different runtimes') | |
plt.title('runtime complexity') | |
plt.grid(True) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment