Hadron DaVinci

Selection Sort Tutorial

06 Mar 2021 - Hadron DaVinci


Example

Sort the given array with Selection Sort:

A = [5, 2, 4, 6, 1, 3]
selection_sort(A)
assert(A) == [1, 2, 3, 4, 5, 6]


Method

  1. Swap the first number and min number in the unsorted space
  2. Reduce the unsorted space
  3. repeat 1.and 2. until the unsorted space is empty

Complexity

Time Complexity: N^2
Space Complexity: 1
Unstable

Code

method1.py