Exam-style question
Try this first
Derive the time complexity of this Python 3 algorithm: for i in range(n): for j in range(i): print(i, j) Give a Big-O classification and justify your answer.
Answer and explanation
Concise answer
The time complexity is O(n^2).
Why this is correct
Although the inner loop does not run exactly n times for every outer-loop iteration, its total number of executions is a triangular sum. That sum grows quadratically, so the algorithm is classified as O(n^2), rather than O(n).
Use the concise answer above for a quick check, then reveal the full model answer and detailed explanation.
Common mistake
No common mistake is linked to this question yet.
