-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbubble_sort.py
25 lines (22 loc) · 876 Bytes
/
bubble_sort.py
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
#!/usr/bin/env python
# coding: utf-8
"""
|------------------------------------------------------------|
| Bubble Sort |
|------------------------------------------------------------|
|Also known as || sinking sort |
|Worst case performance || О(n2) |
|Best case performance || O(n) |
|Average case performance || О(n2) |
|Worst case space complexity || O(1) auxiliary |
|------------------------------------------------------------|
"""
from decorators import timethis
@timethis
def bubble_sort(array):
size = len(array)
for i in range(size):
for j in range(i+1, size):
if array[j] < array[i]:
array[j], array[i] = array[i], array[j]
return array