title: Is This Big O Evaluation Correct?
body: <p>I'm having trouble understanding something. I'm not even sure if it's correct.</p>
  <p>In <em><a href="https://rads.stackoverflow.com/amzn/click/com/0984782850" rel="nofollow noreferrer" rel="nofollow noreferrer">Cracking the Code Interview</a></em>, there is a section that asks you to determine the Big O for a number of functions. For the most part, they're predictable.</p>
  <p>However, one of them throws me for a loop.<br />
  Apparently, this evaluates to <code>O(ab)</code>:</p>
  <pre><code>void printUnorderedPairs(int[] arrayA, int[] arrayB) {
    for (int i = 0; i &lt; arrayA.length; i++){
      for (int j = 0; j &lt; arrayB.length; j++){
        for (int k = 0; k &lt; 100000; k++){
           System.out.println(arrayA[i] + &quot;,&quot; + arrayB[j]);
        }
      }
    }
  }
  </code></pre>
  <p>With the rational that</p>
  <blockquote>
  <p>&quot;100,000 units of work is still constant, so the runtime is <em>O(ab)</em>.</p>
  </blockquote>
  <p>I'm trying to see why this could make sense, but I just can't yet; naturally, I expected <code>O(abc)</code>.</p>
  <p>Yes, <code>100,000</code> is a constant and <code>arrayA</code> and <code>arrayB</code> are arrays, but we're taking the <em>length</em> of the arrays.  At the time of running these <code>for</code> loops, won't <code>array[x].length</code> be a constant (assuming the size of the arrays don't change during their execution)?</p>
  <p>So, is the book right? If so, I would really appreciate insight and intuition so I don't fall into the same trap in the future.</p>
  <p>Thanks!</p>