| | | | | |

Algorithm Complexity - Loops Nested

    for (i = 0; i < n; ++i)
    {
      // 2 atomics in outer loop body
      for (j = 0; j < n; ++j)
      {
        // 3 atomics in inner loop body
      }
    }
    
  • Complexity <= O((2 + 3n)n) <= O(2n + 3n2) <= O(n2)
  • Complexity = Θ((2 + 3n)n) = Θ(2n + 3n2) = Θ(n2)

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