Last active
December 11, 2016 13:46
-
-
Save zedr/3fa39e314d58f4f141e53bbba874cb2a to your computer and use it in GitHub Desktop.
Algorithm: insertion sort
This file contains hidden or 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
# Complexity: O(n^2) | |
def sort(arr): | |
l = len(arr) | |
if l > 1: | |
for ldx in range(l): | |
idx = ldx - 1 | |
key = arr[ldx] | |
while idx > -1 and arr[idx] > key: | |
arr[idx + 1] = arr[idx] | |
idx -= 1 | |
arr[idx + 1] = key | |
return arr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment