Question: are nested for loops always o(n^2)?
Answer: "Are nested for-loops always O(n^2)?" To your other question, the answer is no. They aren't always O(n^2) . ... The loop may, at first glance, look like O(n^2) but the inner loop maximally creates 5 iterations for every iteration of the outer loop. So we receive only 5 * n iterations in total, not something like n^2 .