Review, explain, practice

Study guide: Prepare and Compare Searches

Sort data, count search inspections and trace a first-match binary-search variant.

Download the grade study pack

Ideas to explain in your own words

Watch your reasoning

A worked review example

Trace a Linear Search: Target 5: inspected values 8 → 3 → 11 → 5; return position 3 after 4 inspections. Target 7: inspect all 5 items, return not found. A position and a count differ by one in this first-match case. Trace Insertion Sort: Arrays after passes: [2, 6, 5, 3] → [2, 5, 6, 3] → [2, 3, 5, 6]. The final array is sorted and its items match the original multiset. There are 1 + 1 + 2 = 4 right-shifts of larger items. Trace binary search in a sorted list: Target 31 is larger than 18, so the left side and 18 are discarded. The remaining middle is 31, which matches. Two item inspections found the target. Find the First Matching Sorted Position: Target 4: (lo,hi)=(0,6), mid 3 value 4 → hi 3; mid 1 value 4 → hi 1; mid 0 value 2 → lo 1. Stop at position 1, first 4. Target 5 inspects 4,9,7 and stops at insertion position 4; value 7 is not equal, so report not found.

Make a practice plan

  1. Try the supplied lesson problems without looking at the answers.
  2. Compare your method with the worked examples and explain any correction.
  3. Use the new review cases, then complete the transfer task on paper or in your own document.