mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-19 00:37:02 +00:00
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)
This commit is contained in:
parent
099caeb423
commit
237df47a31
20
sorts/merge_sort_fastest.py
Normal file
20
sorts/merge_sort_fastest.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
'''
|
||||||
|
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 = []
|
||||||
|
a = LIST[0]
|
||||||
|
b = LIST[-1]
|
||||||
|
while (LIST.index(a) == LIST.index(b) and len(LIST) <=2):
|
||||||
|
a = min(LIST)
|
||||||
|
b = max(LIST)
|
||||||
|
start.append(a)
|
||||||
|
end.append(b)
|
||||||
|
LIST.remove(a)
|
||||||
|
LIST.remove(b)
|
||||||
|
end.reverse()
|
||||||
|
return start + end
|
Loading…
Reference in New Issue
Block a user