def g(x): for i in range(x): print(i) def f(n): i = n while i > 0: g(n) i -= 1 6: c_1 7, 9: c_2 8: The cost of line 8 is not a constant, since the function calls g(n), the runtime of which depends on n. So look at g(x). g(x) take time c_3 x. So the cost of line 8 is c_3 n. Line 6: 1 time Lines 7, 9: n times Line 8: n times Total cost: c_1 + c_2 n + c_3 n * n Theta(n^2)