---
title: "Binary Search on Sorted Data"
description: "Finding a value in sorted data by halving the range that is still in play at every step, and the reason the method breaks on unsorted data."
canonical: https://lightmysky.com/learn/computing/binary-search-on-sorted-data-mt_3avV-VasFZ
source: https://lightmysky.com/learn/computing/binary-search-on-sorted-data-mt_3avV-VasFZ.md
retrieved: 2026-09-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Binary Search on Sorted Data

Finding a value in sorted data by halving the range that is still in play at every step, and the reason the method breaks on unsorted data.

Subject: Computing · Area: Programming · Ages 15 to 16
Page: https://lightmysky.com/learn/computing/binary-search-on-sorted-data-mt_3avV-VasFZ

## Ready when they can

- Step through a binary search on a sorted list and count the checks
- Say what happens to the range still being searched after each comparison
- Explain why the data must be sorted, and when that sorting cost is worth paying

## Lesson: Half the suspects each round

Binary search hunts sorted data by halving. Compare the target with the middle item, keep the half that can still hold it, and drop the rest. Every round kills about half of what is left.

**Example.** Hunt 57 in sorted 3, 37, 45, 57, 93 and 120. The middle reads 45, and 57 tops it, so the lower half drops away. The hunt continues in 57, 93 and 120 with far fewer suspects.

The whole trick rests on order. On jumbled data the dropped half might hide the target, so the method breaks. Sort first, then halve.

**Tip.** Sorting costs effort up front, so pay it when many hunts follow. A thousand sorted items need about ten halvings against up to a thousand one-by-one checks.

**Recap.** On sorted data, compare the middle, drop the dead half, and repeat until found or empty.

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Linear Search](https://lightmysky.com/learn/computing/linear-search-mt_32LwZIhSiB)
- [Lists: Many Values Under One Name](https://lightmysky.com/learn/computing/lists-many-values-under-one-name-mt_ipB6kmyK85)
- [Arithmetic in Code: Integer Division and Remainder](https://lightmysky.com/learn/computing/arithmetic-in-code-integer-division-and-remainder-mt_ZPnPrLGPmT)

## Opens up

- [Counting Operations to Compare Algorithms](https://lightmysky.com/learn/computing/counting-operations-to-compare-algorithms-mt_JkN961niFG)
