Python Queue and Deque - Question Bank
Multiple Choice Questions (1 mark each)
1. What is the order of operations in a queue?
A) LIFO B) FIFO C) FILO D) Random
Answer: B
2. Which of the following is a basic queue operation?
A) push B) pop C) enqueue D) insert
Answer: C
3. Which Python module provides a ready-made implementation of a queue?
A) collections B) os C) sys D) queue
Answer: D
4. What happens when we dequeue from an empty queue?
A) It returns 0 B) It appends None C) It raises an error D) It returns an empty string
Answer: C
5. What data structure does a deque represent?
A) Stack B) Queue C) Double-ended queue D) Binary Tree
Answer: C
6. Which method adds an element to the right side of a deque in Python?
A) append() B) appendleft() C) push() D) insert()
Answer: A
7. Which method removes an element from the left end of a deque?
A) pop() B) popright() C) popleft() D) del()
Answer: C
8. Which module contains the deque class?
A) collections B) queue C) functools D) dataclasses
Answer: A
9. What does put() do in a queue?
A) Removes an item B) Adds an item to the queue C) Sorts the queue D) Checks size of queue
Answer: B
10. Which queue type supports enqueue and dequeue from both ends?
A) Simple Queue B) Deque C) Priority Queue D) Stack
Answer: B
Fill in the Blanks (1 mark each)
1. Queue follows the ________ principle. Answer: FIFO
2. The method used to remove an element from a queue is ________. Answer: get()
3. In Python, a deque is implemented using the ________ module. Answer: collections
4. The method ________ is used to add an item at the beginning of a deque. Answer: appendleft()
5. The put() method is used to ________ an item in the queue. Answer: insert/add
2 Marks Questions
1. What is a queue? Give one real-life example.
2. Define enqueue and dequeue operations.
3. What is the role of the queue.Queue class in Python?
4. What happens if you try to get() from an empty queue in Python?
5. Define a deque and explain how it is different from a standard queue.
3 Marks Questions
1. List and explain any three methods of the deque class.
2. Write a Python program to implement a queue using a list.
3. Explain the working of put() and get() methods in Python's queue module.
4. Write a Python snippet to demonstrate adding and removing elements from both ends of a deque.
5. What are the advantages of using deque over list when implementing a queue?
5 Marks Questions
1. Write a Python program to implement all basic queue operations using the queue module.
2. Write a program to implement a deque and perform various operations like append(),
appendleft(), pop(), and popleft().
3. Explain with code how to handle overflow and underflow conditions in a custom queue
implementation.
4. Compare and contrast Queue and Deque with suitable examples.
5. Design a real-life simulation (e.g., print job manager or task scheduler) using Python's queue or
deque.