Skip to content

Instantly share code, notes, and snippets.

@KerryJones
Last active November 2, 2018 19:33
Show Gist options
  • Save KerryJones/95997dffa1ced369203d to your computer and use it in GitHub Desktop.
Save KerryJones/95997dffa1ced369203d to your computer and use it in GitHub Desktop.
Python: Selection Sort
##
# 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