title: Are nested for loops always O(n^2)?
body: <p>I'm struggling coming up with a complexity for this code (this isn't a homework problem, I'm just trying to understand this concept):</p>
  
  <pre><code>public static boolean boxesHaveItem(List&lt;Box&gt; boxes, Item object) {
      for (Box box : boxes) {
          for (Item item : box.getItems()) {
              if (item.equals(object)) {
                  return true;
              }
          }
      }
      return false;
  }
  </code></pre>
  
  <p>Because there are nested for loops, your instict would be O(n^2), but that doesn't make sense because the number of items in a box is unrelated to the number of boxes I'm passing to this method.</p>
  
  <p>Maybe O(mn), where m = average # of items in a box, n = # of boxes?</p>
  
  <p>I was thinking O(n) would be best, where n is the total # of items in all of the boxes passed to the function, but that's kinda weird because they aren't directly passed to the function.</p>