Created
May 29, 2014 17:23
-
-
Save jordanhudgens/a3206d17e24f526b0248 to your computer and use it in GitHub Desktop.
Merge sort implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python version 2.6+ | |
from heapq import merge | |
def merge_sort(m): | |
if len(m) <= 1: | |
return m | |
middle = len(m) / 2 | |
left = m[:middle] | |
right = m[middle:] | |
left = merge_sort(left) | |
right = merge_sort(right) | |
return list(merge(left, right)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment