Linear Search

A linear search walks through an array to determine if a particular object is stored in the array and returns false as soon as an entry greater than the object is found.

The enhanced array- and pointer-based implementations reduce the number of comparisons from three per entry to two. In either case, when the loop ends, the entry at that point is either:

  • The last entry of the array, or
  • The first entry in the array greater than or equal to the object.

In either case, compare that entry and the object and return the result.