In the previous chapter, we explored an algorithm for sorting data known as Bubble Sort, which had an efficiency of O(N^{2}). We’re now going to dig into another sorting algorithm called Selection Sort, and see how it measures up to Bubble Sort.
The steps of Selection Sort are as follows:
We check each cell of the array from left to right to determine which value is least. As we move from cell to cell, we keep in a variable the lowest value we’ve encountered so far. (Really, we keep track of its index, but for the purposes of the following diagrams, we’ll just focus on the actual value.) If we encounter a cell that contains a value that is even less than the one in our variable, we replace it so that the variable now points to the ...
No credit card required