The Selection Card Sort

game

The final sorting algorithm we will learn is the Selection Sort. We will begin by using our playing cards to illustrate the algorithm. Similar to the Simple Sort, the Selection Sort searches through the hand of cards for the smallest card. But unlike the Simple Sort, this sort does not use two hands for sorting. Instead, the Selection Sort uses a marker to divide the sorted and unsorted section of the hand just like the Insertion Sort. The algorithm for the Selection Sort is given in the box below.

Selection Card Sort Algorithm

1. Get a hand of unsorted cards
2. Set a marker for the unsorted section at the front of the hand
3. Repeat steps 4 through 7 until one card remains in the unsorted section
4. Compare all unsorted cards
5. Select the smallest unsorted card
6. Swap this number with the first card in the unsorted section
7. Advance the marker to the right one card
8. Stop

We begin this sort by setting our marker at the front of the hand. Then we search the hand for the smallest card, swap this card with the first card in the unsorted section, and update our marker. By repeating this process of searching and then swapping, we can sort the entire hand of cards.

To see how the Selection Card Sort Algorithm works, click on the animation below. As the sort progresses, the appropriate step of the algorithm will be highlighted in the bottom left panel of the animation. As we did with the Simple Sort, we will keep track of the current cards we are comparing by pointing to them with a pair of human hands. The left hand will point to the smallest card so far, and the right hand will point to the current card for comparison. To divide the sorted and unsorted sections of our hand, we use a black vertical bar.

Publisher: Virginia Tech
Developer: Virginia Tech
Language: en
Year: 2002