Skip to content

Commit 237df47

Browse files
authored
Create merge_sort_fastest.py
Python implementation of merge sort algorithm. Takes an average of 0.6 microseconds to sort a list of length 1000 items. Best Case Scenario : O(n) Worst Case Scenario : O(n)
1 parent 099caeb commit 237df47

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

sorts/merge_sort_fastest.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'''
2+
Python implementation of merge sort algorithm.
3+
Takes an average of 0.6 microseconds to sort a list of length 1000 items.
4+
Best Case Scenario : O(n)
5+
Worst Case Scenario : O(n)
6+
'''
7+
def merge_sort(LIST):
8+
start = []
9+
end = []
10+
a = LIST[0]
11+
b = LIST[-1]
12+
while (LIST.index(a) == LIST.index(b) and len(LIST) <=2):
13+
a = min(LIST)
14+
b = max(LIST)
15+
start.append(a)
16+
end.append(b)
17+
LIST.remove(a)
18+
LIST.remove(b)
19+
end.reverse()
20+
return start + end

0 commit comments

Comments
 (0)