Grade 10 · lesson 1 of 4

Trace a Linear Search

Count comparisons and handle an absent target in an unsorted list.

Download the grade pack

Supplied materials

  • Paper and pencil; an adult may read aloud. No device, account or purchase is needed.

Learn the idea

Linear search checks items one at a time and can work on an unsorted list. State its stopping rule: return the first matching zero-based position; if the list ends without a match, return not found. We count item inspections rather than elapsed time, so our result describes this algorithm on the supplied data.

Pseudocode: for i = 0 through n−1, inspect values[i]; if values[i] equals target, return i; after the loop return not found. Use unsorted fictional codes [8, 3, 11, 5, 2]. For target 5, the algorithm inspects 8, 3, 11 and 5 and stops before inspecting 2.

  1. Write zero-based positions 0..4 over the supplied list.
  2. Trace target 5 and mark every inspected item.
  3. Record returned position and inspection count separately.
  4. Trace absent target 7 and confirm all five items are checked.
Worked example

See the method in action

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.

Your turn

Check your reasoning

Your answer is temporary and is not saved to an account. Download your current answer before leaving or reloading. Written work on paper or in another app stays in your own file.

For target 11 in the supplied list, what are returned position and inspections?

Feedback appears here after you check. This is practice, not a graded school assessment.

See the answer and explanation

Position 2; 3 inspections

The target is at zero-based position 2, after inspecting positions 0, 1 and 2: three inspections.

Take it further

Move target 5 to the front by using [5, 8, 3, 11, 2]. Expected result: position 0 after 1 inspection. The search rule stays the same.

Nothing here is saved to an account or sent to a teacher. The answer download includes your current choice and any checked feedback.

Check the subject sources

These LifeStarter passages, scenarios and exercises are authored for this Academy with AI assistance and review. External resources keep their publishers’ terms. A grade label suggests a starting level; it does not establish alignment with your school’s complete requirements.