A linear search is the simplest method of searching a data set. Starting at the beginning of the data set, each item of data is examined until a match is made. Once the item is found, the search ends. If there is no match, the algorithm must deal with this.
A linear search is the simplest method of searching a data set.
Starting at the beginning of the data set, each item of data is examined until a match is made. Once the item is found, the search ends. If there is no match, the algorithm must deal with this.
A written description algorithm for a linear search might be:
Find out the length of the data set.
Set counter to 0.
Examine value held in the list at the counter position.
Check to see if the value at that position matches the value searched for.
If it matches, the value is found. Send a message and end the search.
If not, increment the counter by 1 and go back to step 3 until there are no more items to search.
If all the items have been checked and no match is found, send a message.