selection_sort

Selection Sort Algorithm

Selection Sort is a simple and efficient sorting algorithm that works by repeatedly selecting the smallest (or largest) element from the unsorted portion of the list and moving it to the sorted portion of the list. The algorithm repeatedly selects the smallest (or largest) element from the unsorted portion and swaps it with the first element of the unsorted portion. This process is repeated for the remaining unsorted portion of the list until the entire list is sorted.

The algorithm maintains two subarrays in a given array.

  • The already sorted subarray.
  • The remaining unsorted subarray.

In every iteration of the selection sort, the minimum (or maximum) element from the unsorted subarray is picked and swaped with the begining element of the unsorted subarray.

After each iteration the sorted subarray size increases by one and the unsorted subarray size decrease by one. After N (size of array) iteration the array gets sorted.

Flowchart of the Selection Sort:

Flowchart for Selection Sort

How selection sort works?

step1
step2
step3
step4
step5
step6
step7
step8
step9
step10
step11
step12
step13

Implementation of the Selection Sort (C++)

[My github repository] (https://github.com/ciaociaocu/Play_with_Algorithm/tree/main/00_Sort_Selection)

Reference


selection_sort
https://ciaociaocu.github.io/2023/01/20/selection-sort/
Author
ciaociao
Posted on
January 20, 2023
Licensed under