| | | | | |

Algorithm Complexity - Sequential Search

T    item  = first(L);
while (item is in L)
{
  if (t == item)
    return true;
  item = next(L);
}
return false;
  • sequential search with early loop break
  • notion of input size: n = size of container
  • atomic computation: comparison (call to operator ==())
  • f(n) = (1 compare in loop body) x (iterations of loop body)
        <= (1) x (n)
        = Θ(n)
  • algorithm complexity <= O(n)
Note that the inequality (which comes from the iteration count) implies that the strongest conclusion to draw is <= O(n) for the algorithm complexity.

| | Top of Page | 1. Introduction to Algorithms: Verification, Complexity, and Searching - 22 of 23