Skip to main content
AP CSP course

F14 · Topic 3.11

Search interval detective

Find present and absent targets while explaining every interval discarded. Compare the measured comparison count with a linear scan.

1. Predict first

For [4,9,13,18,25,31,42] and target 26, predict every middle value and the final result.

Change it · step through · explain

Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.

Ready · Make a prediction

Ready to experiment
  1. Input 14,9,13,18,25,31,42Waiting
  2. Input 226Waiting

Ready to experiment

Why: Predict the first change, then advance one step.

Try this: Try the first and last items, a missing value, duplicates and an empty list.

2. Build your procedure

Write a search procedure using the inclusive low/high invariant. Add a separate linear-search procedure. Keep the input sorted for the binary comparison; do not execute student code in this tool.

Use AP CSP pseudocode, a language you know, or precise plain language. Your code is not executed here. Use the classroom assignment to save your response.

3. Check boundaries

Public worked tests for the fixed model
InputExpectedWhy this case
[]; target 4Absent; 0 comparisonsNo valid interval.
[4]; target 4Position 1; 1 comparisonSmallest successful list.
[4,9,13,18,25,31,42]; target 26Absent; middle values 18,31,25Target between neighbours.

4. Explain and reflect

Why would replacing low ← mid + 1 with low ← mid risk nontermination?

Model limits: The tool rejects unsorted values rather than silently sorting. It traces one fixed search model, not arbitrary submitted code.

Teacher guidance and scoring