Linear search

From Higher Computing Science
Jump to: navigation, search

Key points

  • Linear search is an algorithm that checks an array for the presence of a particular item of data. To do this, the user must be asked what they are searching for. Each item in the array will be compared to the search term, and if the item is found, a message is displayed.

Information

Haggis implementation

 SET list TO [1,4,2,5,3]
 RECEIVE searchterm FROM (INTEGER) KEYBOARD
 FOR counter FROM 0 TO 4 DO
   IF list[counter]=searchterm THEN
     SEND (STRING) searchterm & " found at position " & (STRING) counter
  END IF
 END FOR


Python implementation

Videos

Further information

Test yourself

Teaching resources