Exam-style question
Try this first
Consider this Python 3 code: for item in data: print(item) What is the time complexity in terms of the number of items, n?.
- A.O(1)
- B.O(log n)
- C.O(n)
- D.O(n^2)
Answer and explanation
Concise answer
O(n)
Why this is correct
The loop executes once for each item in data. Therefore, the number of operations grows in direct proportion to 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.
