Results

Cambridge November 2026 results: AS & A Level on 7 January 2027, IGCSE and O Level on 14 January 2027.

Source: Cambridge International
STUDY GUIDE

Binary Search: Worked Trace and Time Complexity

Binary search repeatedly compares a target with the middle item of a sorted search range, then discards the half that cannot contain it. With direct access to list positions, its worst-case number of middle-item checks grows logarithmically with the list size. The sorting requirement and update rules matter: halving an unsorted list does not justify discarding either half.

Book your free 30-minute demo

Updated November 2026.

By LearnAllStudents Editorial Team. Source check dates are listed below.

Worked trace: find 27

Scroll the table to see all columns. Keyboard: focus the table area and use the arrow keys.

Index0123456
Value381219273441

Use inclusive bounds low=0 and high=6 and round the middle index down. First mid=3, value 19. Since 27 is greater, set low=4. The remaining range is indices 4 to 6. Next mid=5, value 34; set high=4. Now mid=4, value 27, so return index 4. This trace uses three middle-item checks. It does not return ‘the fourth value’: the answer is an index using the stated zero-based convention.

Use consistent pseudocode

low ← 0
high ← length(items) - 1
WHILE low <= high
  mid ← low + FLOOR((high - low) / 2)
  IF items[mid] = target THEN RETURN mid
  IF items[mid] < target THEN
    low ← mid + 1
  ELSE
    high ← mid - 1
RETURN NOT_FOUND

The +1 and −1 exclude the already-tested middle item. Without them, a one-item interval can repeat forever. The loop includes equality because a single remaining item still needs testing. This version returns any found occurrence if duplicates exist; finding the first or last occurrence needs additional boundary logic.

Why the growth is logarithmic

After one unsuccessful check, roughly half the candidate positions remain; after two, roughly a quarter; after three, roughly an eighth. A list of 1,023 items can be resolved in at most 10 middle-item checks with this model. Doubling the size adds about one check, rather than doubling the work. Big-O describes how cost grows, not the exact elapsed time on a particular computer.

The model assumes direct access to a middle position and a constant-cost comparison. Traversing a linked list to reach each middle changes the cost. Sorting an unsorted dataset also has a cost, so ‘binary search is always better’ is not a sufficient system-level argument. A one-off search in a tiny unsorted list may be simpler to perform linearly.

Try it yourself

  • Using the seven-item list above, search for 10 and write each middle index.
  • What should an empty-list search return in the stated pseudocode?
  • Why is low=mid potentially unsafe?
  • If 27 occurs twice, does the basic algorithm promise the first occurrence?

Answers: middle indices 3, 1 and 2 are tested, then low=2 and high=1 so the search ends without a match; an empty list returns NOT_FOUND without indexing an item; low=mid can leave the range unchanged; no, the basic algorithm can return either occurrence. For the failed search, keep a table of low, high and mid rather than trying to visualise all changes at once.

For parents: ask what was safely discarded

Give your child a sorted list and a target, then ask them to explain why each removed half cannot contain the target. Change the list to an unsorted order and ask whether the argument still holds. This tests the precondition instead of arithmetic alone. When reviewing code, test an empty list, a one-item match, a one-item miss and a target beyond the final value. Each case reveals a different boundary mistake.

How a tutor would approach this

Bring the search trace or pseudocode. Focus on range boundaries and the stated comparison model before trying to memorise complexity notation.

Frequently asked questions

Must the list be sorted?

Yes, under the same ordering used by the search comparisons. Otherwise discarding half is unjustified.

Is O(log n) an exact time?

No. It describes growth in the chosen cost model, not a number of seconds.

Why move beyond mid?

The middle item has already been checked. Excluding it makes progress and prevents a repeated interval.

Does it always find the first duplicate?

The basic version does not. A first-occurrence search needs additional logic.

Official sources

Related pages

Try a free 30-minute demo

Work through a question with a tutor. No payment needed.

Request a free 30-minute demo
YOUR NEXT STEP

A little clarity starts with 30 minutes.

Share your goals, explore a question and discuss a learning plan. Request your free 30-minute demo class — no payment needed. Tutor and time are confirmed separately.

Book your free 30-minute demo
Book free demoWhatsApp us