Selection sorting

How it works:

  1. finds the smallest element (8), swaps it with the most leftmost element (42), end result is [8, 17, 29, 42, 35]
  2. finds the smallest element from the unsorted part (17), which is already in the correct position, end result is [8, 17, 29, 42, 35]
  3. finds the smallest element from the unsorted part (29), which is already in the correct position, end result is [8, 17, 29, 42, 35]
  4. finds the smallest element from the unsorted part (35), swaps it with 42, end result is [8, 17, 29, 35, 42]
  5. the last element is sorted so, [8, 17, 29, 35, 42]

This process will take 10 comparisons and two swaps

The best case for the selection sort is that it always makes n(nāˆ’1)/2 comparisons, even if the array is already sorted

The worst case for the selectiion sort is that it still makes n(nāˆ’1)/2 comparisons, even if the array is in reverse order