Exam-style question
Try this first
A linear search examines the list [14, 6, 21, 9] for the value 21. How many comparisons are made, and at which zero-based index is the value found?.
- A.2 comparisons, index 1
- B.3 comparisons, index 2
- C.3 comparisons, index 3
- D.4 comparisons, index 2
Model answer
What a good answer should say
- 3 comparisons, index 2
Explanation
Why this works
The search compares 21 with 14, then 6, then 21. Therefore, three comparisons are made and the value is at zero-based index 2.
Common mistake
No common mistake is linked to this question yet.
