2018-05-20 23:00:17 +05:00
|
|
|
'''
|
|
|
|
|
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)
|
|
|
|
|
'''
|
|
|
|
|
def merge_sort(LIST):
|
|
|
|
|
start = []
|
|
|
|
|
end = []
|
2018-05-21 10:21:33 +02:00
|
|
|
while LIST:
|
2018-05-20 23:00:17 +05:00
|
|
|
a = min(LIST)
|
|
|
|
|
b = max(LIST)
|
|
|
|
|
start.append(a)
|
|
|
|
|
end.append(b)
|
2018-05-21 10:21:33 +02:00
|
|
|
try:
|
|
|
|
|
LIST.remove(a)
|
|
|
|
|
LIST.remove(b)
|
|
|
|
|
except ValueError:
|
|
|
|
|
continue
|
2018-05-20 23:00:17 +05:00
|
|
|
end.reverse()
|
2018-05-21 10:21:33 +02:00
|
|
|
return (start + end)
|