Skip to content

Commit

Permalink
Create merge_sort_fastest.py
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
yesIamHasi authored May 20, 2018
1 parent 099caeb commit 237df47
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions sorts/merge_sort_fastest.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 237df47

Please sign in to comment.