Grade 10 · lesson 2 of 4

Trace Insertion Sort

Build a sorted prefix and preserve all supplied items.

Download the grade pack

Supplied materials

  • Paper and pencil; an adult may read aloud. No device, account or purchase is needed.

Learn the idea

Binary search requires sorted input. Sorting is a separate preparation step with its own work. In insertion sort, treat the first item as a sorted prefix; take the next item as key, move larger prefix items one place right, and insert key in the open place. After each pass the prefix grows by one item.

Use fictional codes [6, 2, 5, 3]. On the first pass, key 2 goes before 6. On the second, key 5 goes between 2 and 6. On the third, key 3 goes between 2 and 5. We compare with strict greater-than while shifting, so equal items need not move past each other.

  1. Label the initial one-item sorted prefix [6].
  2. Insert key 2 and write the full array after the pass.
  3. Insert 5, then 3, recording each growing sorted prefix.
  4. Check that the final array is increasing and contains the same four codes.
Worked example

See the method in action

Arrays after passes: [2, 6, 5, 3] → [2, 5, 6, 3] → [2, 3, 5, 6]. The final array is sorted and its items match the original multiset. There are 1 + 1 + 2 = 4 right-shifts of larger items.

Your turn

Check your reasoning

Your answer is temporary and is not saved to an account. Download your current answer before leaving or reloading. Written work on paper or in another app stays in your own file.

After the first insertion-sort pass on [7, 4, 6], what is the full array?

Feedback appears here after you check. This is practice, not a graded school assessment.

See the answer and explanation

[4, 7, 6]

Only key 4 has been inserted into the initial prefix [7]. The last item 6 is not processed until the next pass.

Take it further

Change the input to [6, 2, 5, 5]. Expected final array: [2, 5, 5, 6]; shift counts by pass are 1, 1, 1, totaling 3. Strict > does not shift an equal 5.

Nothing here is saved to an account or sent to a teacher. The answer download includes your current choice and any checked feedback.

Check the subject sources

These LifeStarter passages, scenarios and exercises are authored for this Academy with AI assistance and review. External resources keep their publishers’ terms. A grade label suggests a starting level; it does not establish alignment with your school’s complete requirements.