def f(n): i = 0 while i < n: j = 0 while j < n: print(str(i) + ", " + str(j)) j += 1 i += 1 First, group the lines by frequency that they are run. Let's say that line 2 takes c_1 time each time the function is executed. Let's say that lines 3, 4, and 8 take time c_2 each time the outer loop is executed. Let's say lines 5-7 take c_3 time each time the inner loop is executed. In summary: 2: c_1 3, 4, 8: c_2 5, 6, 7: c_3 How many times is each group of lines executed, in terms of the size of the input, n? Line 2: one time Lines 2, 4, 8: n times Lines 5, 6, 7: n times per execution of outer loop, which is run n times, so that's n^2 So the total run-time is: c_1 * 1 + c_2 * n + c_3 * n^2 Choosing the highest-order term and dropping constants, that's Theta(n^2).