Selection Sort Pseudocode
We'll cover the following...
There are many different ways to sort the cards. Here's a simple one, called selection sort, possibly similar to how you sorted the cards above:
Find the smallest card. Swap it with the first card.
Find the second-smallest card. Swap it with the second card.
Find the third-smallest card. Swap it with the third card.
Repeat finding the next-smallest card, and swapping it into the correct position until the array is sorted.
This algorithm is called selection sort because it repeatedly selects the next-smallest element and swaps it into place.
You can see the algorithm for yourself below. Start by using "Step" to see each step of the algorithm, and then try "Automatic" once you understand it to see the steps all the way through.
After seeing it for yourself, what do you think aout this algorithm? What parts of it seem to take the longest? How do you think it would perform on big arrays? Keep those questions in mind as you go through and implement this algorithm.
Finding the index of the minimum element in a subarray
One of the steps in selection sort is to find the next-smallest card to put into its correct location. For example, if the array initially has values