August 2020
Intermediate to advanced
508 pages
11h 53m
English
Let’s walk through the steps of Selection Sort using the example array, [4, 2, 7, 1, 3].
We begin our first pass-through:
We set things up by inspecting the value at index 0. By definition, it’s the lowest value in the array we’ve encountered so far (as it’s the only value we’ve encountered so far), so we keep track of its index in a variable:

Step 1: We compare the 2 with the lowest value so far (which happens to be 4):

The 2 is even less than the 4, so it becomes the lowest value so far:
Step 2: We compare the next value—the ...
Read now
Unlock full access