May 2019
Beginner
528 pages
29h 51m
English
Selection sort is a simple, but inefficient, sorting algorithm. If you’re sorting in increasing order, its first iteration selects the smallest element in the array and swaps it with the first element. The second iteration selects the second-smallest item (which is the smallest item of the remaining elements) and swaps it with the second element. The algorithm continues until the last iteration selects the second-largest element and swaps it with the second-to-last index, leaving the largest element in the last index. After the ith iteration, the smallest i items of the array will be sorted into increasing order in the first i elements of the array.
As an example, consider the array
34 56 14 20 77 51 93 30 15 52
A program ...
Read now
Unlock full access