Linear Search
- The linear search is a standard algorithm used to find elements in an unordered list. The list is searched sequentially and systematically from the start to the end one element at a time, comparing each element to the value being searched for
- If the value is found the algorithm outputs where it was found in the list
- If the value is not found it outputs a message stating it is not in the list
- An example of using a linear search would be looking for a specific student name in a list or searching for a supermarket item in a shopping list
OUTPUT “Enter a value to find”
INPUT Number
Found ← FALSE
Index ←1
REPEAT
IF Number = Mylist[Index]
THEN
Found ← TRUE
ELSE
Counter ← Counter + 1
ENDIF
UNTIL Found =TRUE OR Counter > LENGTH(Mylist)
IF Found = TRUE
THEN
OUTPUT Number, “ found at position “, Counter
ELSE
OUTPUT Number, “ not found”
ENDIF