Showing AQAChange board

Finding Something Fast

Test yourself on Binary Search with exam style questions, marked instantly.

Flashcards that come back just before you would forget them.

A revision plan that remembers what you know and shows what to do next.

See which topics you have nailed and which need another look.

Quiz yourself on Binary SearchGet your flashcardsBuild my revision planTrack my progress

Finding Something Fast

Binary search is like guessing a number between 1 and 100 when the friend only says "higher" or "lower". You do not start at 1. You guess 50, and every answer lets you throw away half of the numbers. Binary search does the same on a sorted list: check the middle item, decide which half the target must be in, discard the other half, and repeat.

Binary search for 31 in the sorted list 3, 7, 11, 18, 24, 31, 36, 42, 55, 69, at indexes 0 to 9. Step 1: the search range is all ten items, the middle is index 4 with value 24, and 31 is higher. Step 2: the search range is indexes 5 to 9, the middle is index 7 with value 42, and 31 is lower. Step 3: the search range is indexes 5 and 6, the middle is index 5 with value 31, so it is found. Items in the search range are blue, ruled out items are grey and the found item is green.

Binary search needs a sorted list. Each check looks at the middle of the search range, then rules out the half that cannot hold the target. Here 31 is found in 3 checks. The most checks grow very slowly: 10 items need at most 4 checks, and 1,000,000 items need at most 20.

Make this stick

Signing in gives access to all PrepWise features.

PrepWise is a trading name of A3M Quality Solutions Limited, registered in England and Wales, company number 14959172. Registered office: 202 Stroud Road, Gloucester, GL1 5LA. ICO registration ZC267069.