← Quiz: The collections Module: all 10 questions
Quiz: The collections Module · Question 4 of 10
Why is a deque better than a list for a queue?
Why is a deque better than a list for a queue?
- A.A deque can hold more items
- B.A deque keeps its items sorted
- C.Removing from the front is O(1) for a deque but O(n) for a list
- D.A deque uses less memory per item
Answer & explanation
Correct answer: Removing from the front is O(1) for a deque but O(n) for a list
list.pop(0) shifts every remaining item; deque.popleft() does not.
Can you get the rest right without peeking?
Take the timed Quiz: The collections Module quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →