Test yourself on Linear Search with exam style questions, marked instantly.
Flashcards that come back just before you would forget them.
A revision plan that remembers what you know and shows what to do next.
See which topics you have nailed and which need another look.
Quiz yourself on Linear SearchGet your flashcardsBuild my revision planTrack my progressLinear Search Trace Table
To find 19 in [4, 12, 7, 3, 19, 8] (OCR Exam Reference Language style):
found = false
i = 0
while i < 6 AND found == false
if numbers[i] == target then
found = true
else
i = i + 1
endif
endwhile
Linear search checks the items in order from index 0 until it finds the target:
| Check | i | numbers[i] | numbers[i] == 19? |
|---|---|---|---|
| 1 | 0 | 4 | No |
| 2 | 1 | 12 | No |
| 3 | 2 | 7 | No |
| 4 | 3 | 3 | No |
| 5 | 4 | 19 | Yes, found at index 4 |
The target was found after 5 comparisons, so the loop stops and index 5 is never checked. If the target is not in the list, every item is checked and found stays false.
Make this stick
Signing in gives access to all PrepWise features.