Last active
November 2, 2018 19:33
-
-
Save KerryJones/95997dffa1ced369203d to your computer and use it in GitHub Desktop.
Python: Selection 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
## | |
# Selection Sort | |
# | |
# Runtime Complexity: O(n^2) | |
# Space Complexity: O(1) | |
## | |
def selectionSort(arr, detail = False): | |
for i in range(len(arr)): | |
min = i | |
for j in range(i + 1, len(arr)): | |
if arr[j] < arr[min]: | |
min = j | |
arr[min], arr[i] = arr[i], arr[min] | |
if detail: | |
print(arr) | |
return arr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment