Review: Prepare and Compare Searches
Sort data, count search inspections and trace a first-match binary-search variant.
Bring the unit skills together
Use these 4 new cases to check your reasoning. Choices are temporary and are not saved to an account, sent to staff or recorded as school grades. Download your current review choices before leaving or reloading.
The download contains your current choices and any checked feedback. Keep the separate transfer-task work in your own document; downloading its instructions does not mark it complete.
Use the skills in a new task
Prepare fictional codes [8, 2, 5, 2] for first-match searching. Trace insertion-sort passes, then lower-bound search for 2 on the sorted list. Also trace linear first-match search for 5 on the original list and middle-item binary search for 8 on the sorted list, choosing floor((lo+hi)/2) for inclusive binary bounds. Compare inspected-item counts without counting sorting as free.
Work on paper or in your own document. Explain the choices you made.
- Sort with passes [2,8,5,2], [2,5,8,2], [2,2,5,8].
- Find the first 2 at sorted position 0 using lower-bound, inspecting positions 2,1,0.
- Linear search for 5 on original list returns position 2 after 3 inspections.
- Inclusive-bound binary search for 8 inspects values 2,5,8: 3 inspections; state sorting preparation has additional work.
Compare with a model response
Insertion-sort passes: [2,8,5,2] → [2,5,8,2] → [2,2,5,8]. Lower-bound target 2: range [0,4), mid 2 value 5; then [0,2), mid 1 value 2; then [0,1), mid 0 value 2; return 0 after 3 inspections. Linear target 5 on [8,2,5,2] inspects 8,2,5 and returns position 2 after 3 inspections. Binary target 8 with inclusive bounds 0..3 inspects positions 1,2,3, values 2,5,8, also 3 inspections. These small examples do not establish a universal winner, and sorting adds preparation work.
A different response can also meet the criteria. Compare the evidence and reasoning, rather than copying the wording.