One of the main algorithms which can be applied to linked lists, or to arrays, is a serial search. It is the most simple search possible but gives a nice introduction to how searches work. Putting it simply you will two things when doing a serial search; the linked list (or array) and the item you are searching for. There are two possible outcomes; either it finds it or it does not. This can be modeled by an input/output diagram.

When dealing with algorithms, such as serial search, it is important to remember the following –

It is also important to be very specific when defining it. After all when someone comes to program the algorithm they will want to know exactly how it is going to work. If anything is left to chance then the algorithm may not work as intended. When defining algorithms, therefore, we tend to use pseudo code. Below is the pseudo code for a serial search

Inputs – List, Search term

  1. Go to the start of the list and make it the current item to search
  2. Compare the current item with the search term
  3. If they are correct then return a successful result and STOP
  4. Make the current item be the next item in the list.
  5. If there are no more items left in the list then return unsuccessful and STOP
  6. Jump back to step 2

We can convert this so it is even closer to normal code

  1. Input listToSearch[]
  2. Input searchTerm
  3. CurrentItem = 0
  4. For currentItem = 0 to listToSearch.length
  5. If listToSearch[currentItem] = searchTerm then
  6. Return “Item found”
  7. End if
  8. Next
  9. Return “Item not found”