Linear Search Flashcards

All 2 cards in this deck

What are the main steps of a linear search?
e.g. search 4, 9, 2, 7 for the value 2

  1. Compare the first value to the value searched for: 4≠24 \neq 2.
  2. If they match, stop — the item is found.
  3. If not, move to the next value and repeat: 9≠29 \neq 2, then 2=22 = 2 → found.

Other than finding the value, what condition stops a linear search?

The end of the list is reached / every value has been checked (and the value was not found).