3. Serial searching
This is the simplest kind of searching. It is also called the linear search or sequential search
Searching starts with the first item and then moves to each item in turn until either a match is found or the search reaches the end of the data set with no match found.
A criteria is set up before the search begins. e.g. "find the address of customer no 1344"
This criteria will allow a possible match to be found within the records / items stored. If no match is found, then the process will return the appropriate message.
Serial searching algorithm
- Set up the search criteria
- Examine first item in the data set
- If there is a match, end the procdure and return the result with 'match found'
- If no match is found repeat with the next item
- If the last item is reached and no match is found return 'match not found'.
Advantages
Serial search is fairly simple to code. For example the pseudo-code below shows the algorithm in action
procedure serial_search() For i = 0 to 19 check_for_match(i, list) if match_found return 'match found' Next i return 'no match found' end
The subroutine starts with a loop going over a 20 element list / array. Each item is checked until either a match is found or the loop ends and the 'return 'no match found' is reached.
Good performance over small to medium lists. Computers are now very powerful and so checking potentially every element in the list for a match may not be an issue with lists of moderate length.
The list does not need to be in any order. Other algorithms only work because they assume that the list is ordered in a certain way. Serial searching makes no assumption at all about the list so it will work just as well with a randomly arranged list as an ordered list.
Not affected by insertions and deletions. Some algorithms assume the list is ordered in a certain way. So if an item is inserted or deleted, the computer will need to re-order the list before that algorithm can be applied. The overhead of doing this may actually mean that serial searching performs better than other methods.
Disadvantages
May be too slow over large lists. Computers take a finite amount of time to search each item, So naturally, the longer the list, the longer it will take to search using the serial method. The worst case being no match found and every item had to be checked.
This speed disadvantage is why other search methods have been developed.
Challenge see if you can find out one extra fact on this topic that we haven't already told you
Click on this link: Linear search algorithm
Copyright © www.teach-ict.com