One card, one neighbor
The cards on the left are already in order, smallest first. The next card joins them at the right end. Compare it with the card just to its left. If the new card is smaller, move it one place left and compare again. If it is equal or larger, place it there.
Each comparison is with one neighbor. A card larger than the end of the row is placed after one comparison. A card smaller than every card travels all the way to the front.
At the hardest level the practice sorts by selection instead. Keep a candidate for the smallest card, compare it with every remaining card in turn, and only then place it at the end of the ordered row. Finish the whole pass before you place anything.
1Compare the new card with the card on its left.
2Smaller: move it one place left and compare again.
3Equal or larger: place it there.
Four cards: 7, 3, 9, 5
The 7 starts the ordered section. 3 is smaller than 7, so it moves left and reaches the front: 3, 7.
9 is larger than 7, so it is placed after it in one comparison: 3, 7, 9.
5 is smaller than 9, so it moves left. 5 is smaller than 7, so it moves again. 5 is larger than 3, so it is placed there: 3, 5, 7, 9.
Where the comparing starts
The ordered section is 2, 4, 8, 10, and the next card is 5. Follow the method from its first comparison.
Try it
Which card do you compare the 5 with first?
- 10
- 2
Show the answer
10
Right. The new card joins at the right end, so it meets 10 first. 5 is smaller, so it moves left past 10 and then 8, and is placed after 4: three comparisons.
Enable JavaScript to answer interactively and save your place.
Practice Sort with a strategy