Linear and binary search
Algorithms must be understood operationally: how they behave, how to trace them, and when their efficiency makes them suitable.
What you need to be able to do
- Construct + traceAnd trace algorithms to implement a linear search and a binary search for data retrieval
Rapid Recall Deck
Say the answer aloud before flipping. Mark secure knowledge quickly and spend time on the gaps.
- How does a linear search find a target?: It checks elements one by one until it finds the target or reaches the end of the data.
- What prerequisite does binary search have?: The data must be ordered according to the value being searched.
- How does binary search reduce the search space?: It compares with the middle item and repeatedly discards the half that cannot contain the target.
- How do linear and binary search differ in scalability?: Linear search is O(n) in the worst case; binary search is O(log n) when its ordering requirement is satisfied.
- When might linear search be preferable to binary search?: When the data is unsorted, small, or the cost of sorting/indexing would outweigh the benefit of binary search.
Core knowledge and application
And trace algorithms to implement a linear search and a binary search for data retrieval
Algorithms must be understood operationally: how they behave, how to trace them, and when their efficiency makes them suitable.
Explain it without notes
Construct + trace: And trace algorithms to implement a linear search and a binary search for data retrieval in the context of a program that searches and organizes a growing dataset.
- The differences in efficiency between different methods of linear and binary search
- Use of search technique based on efficiency requirements—for example, searching a database for a sorted/indexed list of names to find a phone number, versus searching by the number to identify the name
Programming checkpoint
def binary_search(data, target):
low, high = 0, len(data) - 1
while low <= high:
mid = (low + high) // 2
if data[mid] == target: return mid
if data[mid] < target: low = mid + 1
else: high = mid - 1
return -1static int binarySearch(int[] data, int target) {
int low = 0, high = data.length - 1;
while (low <= high) {
int mid = (low + high) / 2;
if (data[mid] == target) return mid;
if (data[mid] < target) low = mid + 1;
else high = mid - 1;
}
return -1;
}Modify it
Change one condition, input or operation so the program solves a slightly different problem. Predict the effect before editing.
Transfer to a new scenario
- The differences in efficiency between different methods of linear and binary search
- Use of search technique based on efficiency requirements—for example, searching a database for a sorted/indexed list of names to find a phone number, versus searching by the number to identify the name
Paper 2 practice
- Construct + trace: And trace algorithms to implement a linear search and a binary search for data retrieval in the context of a program that searches and organizes a growing dataset.
Finish the learning cycle
IA — main task
Refine Criteria A/B/C. Use today’s lesson to make the problem specification, decomposition, algorithms or testing plan more precise where relevant.
Syllabus — 10–15 min
Repeat the recall deck and complete the lesson response prompt without model support.