LoginSignup
2
1

More than 5 years have passed since last update.

Order graph using python for comparing time complexity

Last updated at Posted at 2018-08-11
import math
import numpy as np
import matplotlib.pyplot as plt 

n = np.arange(5, 10, 0.1)
y = [nn*np.log(nn) for nn in n]
plt.plot(n,y,label="n*log(n)")
y = n 
plt.plot(n,y,label="n")
y = [np.log(nn)**2 for nn in n]
plt.plot(n,y,label="log(n)**2")
y = n**(1/2)
plt.plot(n,y,label="n**(1/2)")
y = [np.log(nn) for nn in n]
plt.plot(n,y,label="log(n)")
plt.legend()
plt.show()

n = np.arange(1,6,1)
y = [math.factorial(nn) for nn in n]
plt.plot(n,y,label="n!")
y = 2**n
plt.plot(n,y,label="2**n")
y = n**2
plt.plot(n,y,label="n**2")
y = n*(n**(1/2))
plt.plot(n,y,label="n*(n**(1/2)")
y = [np.log(nn) for nn in n]
plt.plot(n,y,label="log(n)")
plt.legend()
plt.show()

スクリーンショット 2018-08-11 14.45.58.png
スクリーンショット 2018-08-11 14.46.16.png
log(n) < n^(1/2) < log(n)^2 < n < n*log(n) < n*(n^(1/2)) < n^2 < 2^n < n!

Refs.

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1