| | | | | |

Loop Invariants - Sequential Search

boolean sequential_search
{
  T item = first(L);
  // Before entering loop: t has not been found
  while (item is in L)
  {
    // loop invariant: current item has not been tested
    if (t == item)
      return true;
    // loop invariant: t is not current item
    item = next(L);
  }
  return false;
}

| | Top of Page | 3. Introduction to Algorithm Analysis - 12 of 23