Skip to content

Instantly share code, notes, and snippets.

@ShamsAnsari
Last active April 16, 2020 01:42
Show Gist options
  • Save ShamsAnsari/65bb38b570aa0fd7e329de927264a013 to your computer and use it in GitHub Desktop.
Save ShamsAnsari/65bb38b570aa0fd7e329de927264a013 to your computer and use it in GitHub Desktop.
def selection_sort(arr: []):
# Traverse through all array elements
for i in range(len(arr)):
# Find the minimum element in remaining
# unsorted array
min_idx = i
for j in range(i+1, len(arr)):
if arr[min_idx] > arr[j]:
min_idx = j
# Swap the found minimum element with
# the first element
arr[i], arr[min_idx] = arr[min_idx], arr[i]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment