A warehouse program searches the following inventory records in increasing index order. Each request starts a fresh sequential search at index 0.
Index
Code
Units available
0
PX
1
QJ
5
2
3
MN
7
4
6
The program uses short-circuit evaluation: it first tests whether the record's code equals the requested code, and it tests the quantity only when the code matches. The quantity test checks whether available units are greater than or equal to the requested minimum. The search stops at the first record passing both tests, or after the last record if none qualifies.
Complete the table with the exact integer number of code tests and quantity tests executed for each request. Count only these two kinds of test; ignore loop-control tests.
Unlock full course notes by signing up
Comparison cost of a search workload
A help-desk app performs 30 independent linear searches of a 60-element list. Fourteen searches first match at index 0, nine first match at index 23, and seven have absent targets. Each search starts at index 0, stops at its first match, and reuses no previous result. Find the total number of equality comparisons as an exact integer and the mean number per search to one decimal place.
Fit a worst-case search within a time budget
A device designer models each element-to-target equality comparison as taking exactly 3 microseconds. The model ignores all other costs. An unsuccessful linear search must finish within 1.2 milliseconds, including that limit. What is the maximum list length the model allows? Answer in elements, to zero decimal places.
Repair the complete search behavior
A programmer intends this Python function to return the first matching zero-based index, or -1 if the target is absent. Examine its behavior for empty lists, last-element matches, and duplicates. Which statements are true? Select all that apply.
Count absent targets under early stopping
A device stores the integer identifiers [12, 19, 31, 44] in ascending order. Its sequential search starts at index 0 and checks one stored integer at a time:
If the stored integer equals the target, report found and stop.
If the stored integer exceeds the target, report absent and stop.