Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import log
- # Create the 2 basic functions f(n) and g(n)
- f = lambda n : n**2
- g = lambda n : n**3
- logf = lambda n : log(f(n), 2)
- logg = lambda n : log(g(n), 2)
- expf = lambda n : 2**f(n)
- expg = lambda n : 2**g(n)
- import matplotlib.pyplot as plt
- numbers = list(range(1, 11))
- # numbers = [1, 2, 3, .... , 9, 10]
- # 1st plot
- plt.plot([f(n) for n in numbers], label="f(n) = n^2")
- plt.plot([g(n) for n in numbers], label="g(n) = n^3")
- plt.xlabel("n")
- plt.ylabel("T(n)")
- plt.legend()
- plt.show()
- # 2nd plot
- plt.plot([logf(n) for n in numbers], label="logf(n) = log(n^2)")
- plt.plot([logg(n) for n in numbers], label="logg(n) = log(n^3)")
- plt.xlabel("n")
- plt.ylabel("T(n)")
- plt.legend()
- plt.show()
- # 3rd plot
- plt.plot([expf(n) for n in numbers], label="2 ^ f(n) = 2 ^ (n^2)")
- plt.plot([expg(n) for n in numbers], label="2 ^ g(n) = 2 ^ (n^3)")
- plt.xlabel("n")
- plt.ylabel("T(n)")
- plt.legend()
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement