-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbigO.py
More file actions
65 lines (44 loc) · 1.22 KB
/
bigO.py
File metadata and controls
65 lines (44 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
Big-O notation image generator. Code which generated the Big-O
growth graph (order) in the book.
"""
import numpy as np
import math
import matplotlib.pyplot as plt
from functools import reduce
def f(t):
return np.exp(-t) * np.cos(2*np.pi*t)
def k(t):
return [0]
def l(t):
return list(map(math.log, t))
def x(t):
return list(map(lambda x: x, t))
def xl(t):
return list(map(lambda x: math.log(x)*x, t))
def sq(t):
return list(map(lambda x: x*x, t))
def p2(t):
return list(map(lambda x: pow(2,x), t))
def fact(n):
return reduce(lambda x,y : x*y, range(1, n+1))
def facn(t):
return list(map(lambda x: fact(x), t))
t = range(1, 101)
plt.axis([0, 50, 0, 50])
line1=plt.plot(t, [1]*100, '#00ee00')
print(line1)
plt.text(45, 1.5, r'O(1)')
line2=plt.plot(t, l(t), color='#00bb00')
plt.text(40, 4.8, r'O(log(n))')
line3=plt.plot(t, x(t), color='#008800')
plt.text(42, 40, r'O((n))')
line4=plt.plot(t, xl(t), color='#eeee00')
plt.text(18, 45, r'O(nlog(n))')
line5=plt.plot(t, sq(t), color='#440000')
plt.text(8, 44, r'O(n^2)')
line6=plt.plot(t, p2(t), color='#bb0000')
plt.text(2, 35, r'O(2^n)')
line7=plt.plot(t, facn(t), color='#ff0000')
plt.text(0, 45, r'O(n!)')
plt.show()