title: I need help understanding how to find the Big-Oh of a code segment
body: <p>My Computer Science II final is tomorrow, and I need some help understanding how to find the Big-Oh for segments of code. I've searched the internet and haven't been able to find any examples of how I need to understand it.</p>
  
  <p>Here's a problem from our sample final:</p>
  
  <pre><code>for(int pass = 1; i &lt;= n; pass++)
  {
      for(int index = 0; index &lt; n; index++) 
          for(int count = 1; count &lt; n; count++) 
          {
              //O(1) things here.
          }
      }
  }
  </code></pre>
  
  <p>We are supposed to find the order (Big-Oh) of the algorithm. </p>
  
  <p>I <em>think</em> that it would be O(n^3), and here is how I came to that conclusion</p>
  
  <pre><code>for(int pass = 1; i &lt;= n; pass++) // Evaluates n times
  {
      for(int index = 0; index &lt; n; index++) // Evaluates n * (n+1) times
          for(int count = 1; count &lt; n; count++) // Evaluates n * n * (n) times
          {
              //O(1) things here. 
          }
      }
  }
  // T(n) = (n) + (n^2 + n) + n^3
  // T(n) = n^3 + n^2 + 2n
  // T(n) &lt;= c*f(x)
  // n^3 + n^2 + 2n &lt;= c * (n^3)
  // O(n) = n^3
  </code></pre>
  
  <p>I'm just not sure if I'm doing it correctly. Can someone explain how to evaluate code like this and/or confirm my answer?</p>