-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbigO.py
More file actions
51 lines (36 loc) · 843 Bytes
/
Copy pathbigO.py
File metadata and controls
51 lines (36 loc) · 843 Bytes
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
import timeit
import numpy as np
import matplotlib.pyplot as plt
#Big-O Notation Practice
#O(n + 10) => O(n)
#O(100 * n) => O(n)
#O(50) => O(1)
#O(n2 + n3) => O(n3)
#O(n + n + n + n + n) => O(n)
x = [2, 4, 6, 8, 10, 12]
y = [2, 2, 2, 2, 2, 2]
#plt.plot(x, y, 'b')
#plt.xlabel('Inputs')
#plt.ylabel('Steps')
#plt.title('Constant Complexity')
#plt.show()
def linear_algo(items):
for item in items:
print(item)
#linear_algo([4, 5, 6, 8])
def linear_algo(items):
for item in items:
print(item)
for item in items:
print(item)
#linear_algo([4, 5, 6, 8])
def quadratic_algo(items):
for item in items:
for item2 in items:
print(item, ' ' ,item)
quadratic_algo([4, 5, 6, 8])
plt.plot(x, y, 'b')
plt.xlabel('Inputs')
plt.ylabel('Steps')
plt.title('Linear Complexity')
plt.show()