Linear Search

You need to be able to write algorithms to search and add items to a linear list.

Search a linear list

Searching a linear list for a particular item of data is known as a linear search.  This involves visiting each item of data in turn and testing it to see if it is the target value.  This can be done programmatically with an iteration construct.  This can be done using an iteration construct such as a REPEAT/UNTIL loop or a FOR/NEXT loop.

Algorithm

Start at beginning of list
Repeat
        Test next item for a match
Until item found or end of list

 

Add an item to a linear list

This involves scanning the list for the next available free space.

Algorithm

Start at beginning of list
Repeat
        Test if next place in list is free
        If so, add new item to list
        Else, report list is full
Until end of list