Grade 10 · lesson 3 of 4

Trace binary search in a sorted list

Explain how sorted order allows part of a search range to be discarded.

Download the grade pack

Supplied materials

  • Sorted fictional item codes: [4, 9, 13, 18, 24, 31, 45]. Target for the worked case: 31.
  • Algorithm: inspect the middle remaining item. If the target is larger, keep only the items to its right; if smaller, keep only those to its left; if equal, finish.

Learn the idea

Binary search uses sorted order. A comparison with the middle item tells you which half cannot contain the target. Without sortedness, discarding a half could discard the answer.

Count inspected items rather than pretending the computer guesses. If no items remain, report “not found.” A failed search is a valid result; it should not return an unrelated nearby item.

  1. Inspect the middle value 18 in the seven-item list.
  2. For target 31, keep [24, 31, 45].
  3. Inspect its middle and finish if it matches.
  4. Repeat from the original list for target 9.
Worked example

See the method in action

Target 31 is larger than 18, so the left side and 18 are discarded. The remaining middle is 31, which matches. Two item inspections found the target.

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.

Starting again with the original list, what is the second inspected value when searching for 9?

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

See the answer and explanation

9

The first middle is 18. Since 9 is smaller, the remaining range is [4, 9, 13], whose middle is 9. The reasoning relies on the supplied sorted order.

Take it further

Search for 12 and trace 18 → 9 → 13 → not found. Then explain why binary search must not be used on the unsorted list [18, 4, 45, 9, 31, 13, 24] without preparation.

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

Longer courses for learners ages 14+

These related courses have their own preparation and projects. They are not early-grade assignments.

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.