Algorithm


Selection Sort Algorithm:

  1. Start with an unsorted array.
  2. For each element in the array:
    1. Set the current element as the minimum.
    2. Traverse the remaining unsorted portion of the array.
    3. If a smaller element is found, update the minimum to this element.
    4. Swap the minimum element with the first unsorted element.
  3. Repeat the process for the next unsorted element until the entire array is sorted.

Example:

Selection Sort Example

Fig. 1: Iteration by Iteration Visualization of Selection Sort

Note: Selection Sort ensures that, after each pass, the smallest unsorted element is placed in its correct position.