Skip to content

Commit 12745c9

Browse files
committed
Big o - run time complexity
1 parent be582e8 commit 12745c9

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

  • algorithm_and_datastructure/bigO
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
@Author: Aseem Jain
3+
@profile: https://www.linkedin.com/in/premaseem/
4+
O(Log(n))
5+
"""
6+
7+
n = 10
8+
9+
10+
def logn():
11+
total_operation = 0
12+
t = 1
13+
while t < n:
14+
total_operation += 1
15+
t = t * 2
16+
return total_operation
17+
18+
def On():
19+
total_operation = 0
20+
t = 1
21+
while t < n:
22+
total_operation += 1
23+
t = t +1
24+
return total_operation
25+
26+
def Nlogn():
27+
total_operation = 0
28+
t = 1
29+
for i in range(n):
30+
t = 1
31+
while t < n:
32+
total_operation += 1
33+
t = t * 2
34+
return total_operation
35+
36+
def nSquare():
37+
total_operation = 0
38+
ot = 1
39+
while ot < n:
40+
ot += 1
41+
t = 1
42+
while t < n:
43+
total_operation += 1
44+
t = t + 1
45+
46+
return total_operation
47+
48+
def nexpn(p,total_operation):
49+
if p == 10:
50+
return 1
51+
for i in range(10):
52+
total_operation += 1
53+
54+
return total_operation + nexpn(p+1,total_operation)
55+
56+
57+
print("total operation would be log n: ",logn())
58+
print("total operation would be N: ",On())
59+
print("total operation would be N log n: ",Nlogn())
60+
print("total operation would be N Square: ",nSquare())
61+
print("total operation would be N exp n: ",nexpn(1,2))
62+
63+
64+

0 commit comments

Comments
 (0)