OCR J277 · Computational thinking, algorithms and programming
Searching and sorting revision
Trace linear and binary search, bubble sort, insertion sort and merge sort and explain their conditions and trade-offs.
What to know about searching and sorting
Linear search
Inspect items in sequence until the target is found or the collection is exhausted. It works on unsorted data. A search can stop at the first match if the task asks for one occurrence; finding every occurrence needs a different stopping rule. If n items contain no target, a straightforward linear search may check all n.
Binary search
Binary search requires sorted data and discards half of the remaining range after checking its middle item. In [4, 11, 18, 26, 35, 47, 59], searching for 47 first checks 26, then continues in the higher half. With inclusive low/high indices, a lower target sets high = mid−1 and a higher target sets low = mid+1. Excluding the tested middle prevents a non-progressing search.
Focus areas: Searching and sorting.
Test yourself: questions and answers
Answer each prompt from memory before opening the explanation. These 4 samples come from this topic's 12 original retrieval cards.
Does linear search require sorted data?
No. It can inspect an unsorted collection sequentially.
What prerequisite does binary search need?
The data must be sorted in the order used by the search.
What does binary search discard after a comparison?
The half that cannot contain the target, along with the tested middle if it did not match.
What kind of comparisons does bubble sort repeatedly make?
Comparisons of adjacent items, swapping out-of-order pairs.
Worked examples for this topic
Linear search vs binary search: examples and trace tables — Trace both searches on the same list and explain why binary search needs sorted data.
Turn this topic into a revision session
- Explain one idea without looking at the notes.
- Compare your answer with the guidance and identify the missing link.
- Apply it in a question or short program, then revisit it after a delay.
Free accounts choose one revision topic pack. Pro includes all 26 packs in this course and both published qualifications. Public samples and coding practice are free; PDF guides are separate purchases.
Create a free accountSpecification and sources
Check the required scope against the official OCR J277 specification (PDF). RecallStride's explanations and examples are independent learning resources. See our editorial policy or report a correction, including the topic code and statement concerned.