| | | | | |

Algorithm Complexity - Sequential Search (Simplified)

    T    item  = first(L);
    bool found = false;
    while (item is in L)
    {
      if (t == item)
        found = true;
      item = next(L);
    }
    return found;
    
  • simplified sequential search (no early break from loop)
  • 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 = Θ(n)

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