Insert each card from the right end

Compare the new card with its left neighbor, move it left while it is smaller, and place it when it is not

One card, one neighbor

Ordered37Next9Waiting5
The ordered section, and the next card waiting to join it.

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.

More

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.

Lesson help

Compare the new card with its left neighbor, move it while it is smaller, and place it when it is not.

About this lesson

Try the method in a practice when you are ready.

Report

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.

Ordered37Next9Waiting5
The ordered section, and the next card waiting to join it.

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.

Ordered379Next55 < 9, move. 5 < 7, move. 5 > 3, place.
The last card meets the row at its right end.

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.

Ordered24810Next5
Four ordered cards and one new card.

Try it

Which card do you compare the 5 with first?

  1. 10
  2. 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

Sign in free

Practice without limits and keep your progress.