Linear Search
This is a simple algorithm used to find a value in a list of
- Identify a search term.
- Look at the first item in the list.
- Compare the item with the search term.
- Is the current item the same as the search term? If so, the item has been found. If not, move to the next item.
- Repeat from step two until the last item in the list has been reached.
- If the end of the list has been reached and the search term has not been found, then the search term is not in the list and the algorithm can stop.
In
find <-- 1 found <-- False length <-- length(list) counter <-- 0 WHILE found = False AND counter <= length IF list[counter] = find THEN found <-- True OUTPUT 'Found at position', counter ELSE counter <-- counter + 1 ENDIF ENDWHILE IF found = False THEN OUTPUT 'Item not found' ENDIF