Question:medium

In Python, ________ module needs to be imported for implementing a Double-Ended Queue?

Updated On: Jan 16, 2026
  • counter
  • collections
  • random
  • numpy
Show Solution

The Correct Option is B

Solution and Explanation

To create a Double-Ended Queue (Deque) in Python, import the collections module. This module offers specialized containers beyond Python's standard ones like lists, dictionaries, and tuples. Among these is deque, designed for efficient, thread-safe additions (appends) and removals (pops) from both ends, with near constant O(1) time complexity regardless of the direction.
Initialization of a deque is demonstrated below:

from collections import dequedq=deque()

The deque object supports methods such as append() and appendleft() for inserting elements at the right and left ends respectively, and pop() and popleft() for removing elements from the right and left ends.

Was this answer helpful?
0