VIRTUAL LABS

Logo

Linear Search Algorithm


Algorithm Steps:

  1. Start at the first element of the array.
  2. Compare the current element with the target value.
  3. If they match, return the index of the current element.
  4. If not, move to the next element in the array.
  5. Repeat the process until you find the target or reach the end of the array.
  6. If the target is not found, return a value indicating that it is not present (often -1).

Example:

For instance, to find the number 8 in the list [12, 25, 8, 10, 32], the algorithm will check each element one by one until it finds the number.

Linear Search Example