Your mate wore bib 42 in a York fun run. How would you find their entry?
Your mate wore bib forty-two in a York fun run. You have the entry list, but the bib numbers are in the order people signed up. How would you find their entry?
Start at the top of the race list. Position one holds bib eighteen. Position two holds bib forty-two, position three holds bib seven, and position four holds bib thirty-one. The position tells you where the entry is. The bib number tells you which runner it belongs to.
Watch what happens when you look for bib forty-two. The first entry is eighteen, so move on. The next entry is forty-two, so stop there. You don’t need to check the two entries that come after it.
You’re looking for bib twenty-seven in a new list. The first entry is fourteen, so the comparison fails. What should the search do now? Pick the answer that shows its very next step.
This is called linear search. Start at the first entry and check one entry at a time. If an entry matches the target, report where you found it. If you reach the end without a match, report that the target wasn’t found.
Trace this search for forty-two. At position one, eighteen doesn’t match. Neither does seven at position two, nor thirty-one at position three. The fourth entry matches, so stop and report position four. You made four comparisons.
Now search for bib fifty in a different list. Trace the entries from the start, just as you did before. What will the search report, and how many comparisons will it make? Pick an answer.
Compare fifty with twelve. A first mismatch only rules out twelve, so keep going. Sixty-three doesn’t match, eight doesn’t match, and twenty-four doesn’t match either. Now there are no entries left to compare, so report not found.
The bibs are sorted. Compare thirty-one with the middle bib, twenty-four. Thirty-one is larger, so keep only the entries to the right. Now thirty-one is below the middle bib, forty-two, so keep only the left entry. Thirty-one matches. That’s binary search. If no entries remain, report not found.
If Paper One asks you to compare the searches, start with the list. Linear search works on unsorted lists, while binary search requires sorted data. Then compare the work they do. If the target is missing, linear search checks every entry. Binary search discards about half at each mismatch.