Exam-style question
Try this first
Consider this Python 3 code: for i in range(n): for j in range(n): print(i, j) What is the time complexity?.
- A.O(1)
- B.O(log n)
- C.O(n)
- D.O(n^2)
Answer and explanation
Concise answer
O(n^2)
Why this is correct
The outer loop runs n times and, for each of those iterations, the inner loop also runs n times. This gives n multiplied by n operations, or O(n^2), which is polynomial time.
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.
