lesson

Halving needs ordered data

1 · Learn

Binary search compares a target with a middle item in an ordered list, then discards the half that cannot contain the target. Repeating this can use fewer comparisons than checking every item, especially for long lists.

The ordering precondition is essential. On an unsorted list, discarding a half can discard the target. Count the cost of preparing or maintaining order when comparing complete solutions, not only the search step.

Sorted inputMiddle comparisonDiscard impossible halfRepeat
Key words and supplied examples.

2 · Worked example

For sorted [2,5,8,11,14,17,20], the middle is 11. To find 17, keep the upper part; its middle is 17, found on the second comparison in this trace.

3 · Your turn

Why is binary search unsafe as described on [8,2,17,5,11]?

Check your answer

The list is not sorted, so a middle comparison does not identify a half guaranteed to exclude or contain the target.

4 · Apply your learning

Trace present and absent targets on a sorted list and record the interval remaining after each comparison.

Adult guidance and safety

Use an approved private interpreter, simulator or authoring tool with fictional data. Trace and predict before running. Never execute unknown downloaded code, inspect real credentials or use other people's private data. Working examples still need saved-project and assessment integration before release.

Open your writing and drawing pad

Write, draw or show your working. Use a mouse, pen or finger. This pad is not a submitted answer.

Not saved to your account. Download your drawing as PNG and your typed notes as TXT before leaving or refreshing. They are separate files. Do not enter private information.

Open a picture saved on this device to draw on it again. Opening replaces the drawing, but Undo can restore it. PNG only, up to 4 MB and 4096 × 4096 pixels. The picture stays in this browser; it is not uploaded. Paper lines in a saved picture become part of that picture.

Drawing is unavailable. Use the typed working area below.

Your pad is empty.

Open a UTF-8 TXT file from this device, up to 40 KB and 10,000 characters. It stays in this browser. Opening can be undone until you type again. Downloads keep a new copy; they do not change the file you opened.

Typed notes are not submitted answers.

Check a calculation · Year 5 onward

Use this only when your teacher or adult allows a calculator for the task. Show your thinking first. It does not replace mental or written arithmetic and does not mark your lesson answer.

Powers, roots and trigonometry · Year 7 onward

Use only when the task allows a calculator. Choose one operation at a time and record your working. Trigonometry here always uses degrees (DEG), not radians. Inverse sine, cosine and tangent return an angle, not a reciprocal. Keep exact fractions and π in answers when requested.

Approximate numerical results use up to 12 significant digits. Inverse sine returns −90° to 90°, inverse cosine 0° to 180°, and inverse tangent −90° to 90°; these are principal values, not every possible solution of a trigonometric equation.

Practice this lesson

Lesson resources

Browse the available practice activities and worksheets for this lesson.

Open course resources

Your progress

Ready to continue?