Skip to content

Commit 383e038

Browse files
committed
polynomial time big o
1 parent 494de57 commit 383e038

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

complexity/04-polynomial_time.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Polynomial Time -> O(n^x)
3+
"""
4+
5+
numbers = [64, 34, 25, 12, 22, 11, 90]
6+
7+
8+
def bubble_sort(collection):
9+
length = len(collection)
10+
for i in range(length-1):
11+
swapped = False
12+
for j in range(length-i-1):
13+
if collection[j] > collection[j+1]:
14+
swapped = True
15+
collection[j], collection[j+1] = collection[j+1], collection[j]
16+
if not swapped:
17+
break
18+
return collection
19+
20+
21+
# O(n^2)
22+
print(bubble_sort(numbers))

0 commit comments

Comments
 (0)