CBSE Class XII Computer Science – Queue & Deque (Question Bank)
50 Multiple Choice Questions (MCQs)
1. Which data structure follows FIFO principle?
Answer: Queue
2. What does FIFO stand for?
Answer: First In First Out
3. Which operation adds an element to a queue?
Answer: Enqueue
4. Which operation removes an element from a queue?
Answer: Dequeue
5. What happens when trying to remove an element from an
empty queue?
Answer: Underflow
6. What is the opposite of underflow?
Answer: Overflow
7. Which Python structure can be used to implement a queue?
Answer: List or collections.deque
8. In which end is data added in a queue?
Answer: Rear
9. From which end is data removed in a queue?
Answer: Front
10. What type of queue allows insertion and deletion from
both ends?
Answer: Deque
11. Full form of Deque?
Answer: Double Ended Queue
12. Which queue type gives priority to elements?
Answer: Priority Queue
13. What happens when queue capacity is full?
Answer: Overflow condition
14. Which operation is used to view the front element
without removing it?
Answer: Peek
15. Which function checks if a queue is empty in Python?
Answer: len(queue)==0
16. What is the time complexity for insertion in a queue?
Answer: O(1)
17. Which module in Python provides deque?
Answer: collections
18. Which end of a deque allows addition?
Answer: Both ends
19. In circular queue, what happens when rear reaches end?
Answer: It wraps around to the beginning
20. Which method adds element to right end in deque?
Answer: append()
21. Which method removes element from right end in deque?
Answer: pop()
22. Which method adds element to left end in deque?
Answer: appendleft()
23. Which method removes element from left end in deque?
Answer: popleft()
24. What is the maximum number of elements that can be held before
overflow?
Answer: Queue capacity
25. Queue is a ______ data structure?
Answer: Linear
26. Deque supports both ______ and ______ operations at both
ends.
Answer: Insertion, Deletion
27. Which queue implementation avoids wastage of space?
Answer: Circular Queue
28. In Python list, front of queue is at index?
Answer: 0
29. Which condition represents empty circular queue?
Answer: front == -1
30. Which condition represents full circular queue?
Answer: (rear+1) % size == front
31. Which type of queue is useful in printer scheduling?
Answer: Priority Queue
32. Can deque act as both stack and queue?
Answer: Yes
33. What does ‘front’ pointer represent in queue?
Answer: First element position
34. What does ‘rear’ pointer represent in queue?
Answer: Last element position
35. Which exception is raised when dequeuing from empty
queue?
Answer: IndexError
36. What type of queue is implemented in CPU scheduling?
Answer: Circular Queue
37. In deque, which function clears all elements?
Answer: clear()
38. Which data structure can represent both LIFO and FIFO?
Answer: Deque
39. Which module’s deque is thread-safe?
Answer: collections.deque
40. Which method returns length of deque?
Answer: len()
41. Which queue has limited size?
Answer: Bounded Queue
42. Which queue doesn’t have limit?
Answer: Unbounded Queue
43. What is rear initialized to in empty queue?
Answer: -1
44. In queue, if front = rear = -1, then queue is?
Answer: Empty
45. Which function removes and returns an element in deque?
Answer: popleft() or pop()
46. What is time complexity of dequeue operation?
Answer: O(1)
47. In which scenario do we use circular queue?
Answer: When we need efficient use of space
48. Which queue type allows priority-based deletion?
Answer: Priority Queue
49. What happens if rear < front in circular queue?
Answer: Queue wrapped around
50. Deque provides insertion/removal at how many ends?
Answer: Two
1-Mark Questions
1. Define Queue.
Answer: Queue is a linear data structure that follows FIFO principle.
2. What does FIFO stand for?
Answer: First In First Out.
3. What is overflow in queue?
Answer: When insertion is attempted on a full queue.
4. What is underflow?
Answer: When deletion is attempted on an empty queue.
5. What is the difference between queue and stack?
Answer: Queue follows FIFO while stack follows LIFO.
6. Name the operations on queue.
Answer: Enqueue and Dequeue.
7. Which module provides deque in Python?
Answer: collections module.
8. What is a circular queue?
Answer: Queue where last position connects back to first position.
9. Which operation removes element from queue?
Answer: Dequeue.
10. What is a deque?
Answer: A double-ended queue allowing insertion/deletion at both ends.
2-Mark Questions
1. Explain enqueue and dequeue operations.
Answer: Enqueue adds an element at the rear, while dequeue removes an element
from the front.
2. Differentiate between linear queue and circular queue.
Answer: Linear queue wastes space after deletions; circular queue reuses space
by wrapping around.
3. What is the advantage of using deque?
Answer: Deque allows insertion and deletion from both ends, increasing
flexibility.
4. Write Python function to check if queue is empty.
Answer: def isEmpty(q): return len(q)==0
5. What happens when front > rear in circular queue?
Answer: It means the queue has wrapped around.
6. What is the use of collections.deque?
Answer: Efficient implementation of stack and queue operations.
7. What are the limitations of list-based queue?
Answer: Inefficient for large data due to shifting of elements during deletion.
8. What are the two ends of a queue called?
Answer: Front and Rear.
9. What is the role of front and rear pointers?
Answer: Front points to first element; rear points to last element.
10. Explain overflow and underflow with examples.
Answer: Overflow: adding to full queue; Underflow: removing from empty queue.
3-Mark Questions
1. Explain the working of a circular queue with an example.
Answer: In circular queue, when rear reaches end, it wraps around to front if
space is available. Example: For queue size 5, after enqueuing and dequeuing
some elements, rear may reuse freed spaces.
2. How can a deque act as both stack and queue?
Answer: Deque supports append/pop from both ends, allowing FIFO (queue) and
LIFO (stack) behavior.
3. List three real-life applications of queue.
Answer: Printer scheduling, call center systems, CPU task scheduling.
4. Write a Python code to implement enqueue operation.
Answer: def enqueue(q, item): q.append(item)
5. Explain peek operation in queue.
Answer: Peek displays front element without removing it.
6. Describe how underflow and overflow conditions are
detected.
Answer: Underflow: when front == -1; Overflow: when (rear+1)%size==front.
7. Differentiate between simple queue and priority queue.
Answer: Simple queue serves elements by order; priority queue serves based on
priority value.
8. State three advantages of deque over list.
Answer: Deque provides faster append/pop operations, supports both ends, and is
thread-safe.
9. What is the purpose of clear() method in deque?
Answer: It removes all elements from deque instantly.
10. Give algorithm for checking full queue in circular
queue.
Answer: IF (rear+1)%size == front THEN queue is full.
5-Mark Questions (Detailed Answers)
1. Explain in detail the implementation of queue using list
in Python.
Answer: In Python, a queue can be implemented using a list. Enqueue operation
uses append() to insert at the end. Dequeue operation uses pop(0) to remove the
front element. Overflow and underflow can be checked by maintaining max size
and verifying conditions before enqueue/dequeue.
2. Describe circular queue in detail with diagrammatic
explanation.
Answer: Circular queue connects the end of queue to the front forming a circle.
It prevents space wastage in linear queues. When rear = size-1, new element is
inserted at index 0 if it's free. The condition (rear+1)%size == front means
the queue is full.
3. Explain all major operations performed on deque with
Python methods.
Answer: Deque supports append() and appendleft() for insertion; pop() and
popleft() for deletion; clear() to empty deque; extend() to add multiple
elements; and rotate() to rotate elements. It’s efficient and thread-safe.
4. Discuss applications of queue and deque in real life.
Answer: Queues are used in CPU scheduling, printer jobs, call queues, etc.
Deques are used for palindrome checking, undo mechanisms, and storing history
in browsers. Both provide structured data flow control.
5. Write an algorithm to implement enqueue and dequeue
operations in a circular queue.
Answer: Algorithm Enqueue:
1. Check if full (if (rear+1)%size == front).
2. If not full, update rear = (rear+1)%size and insert element.
Algorithm Dequeue:
1. Check if empty (if front == -1).
2. If not empty, remove element at front and update front = (front+1)%size.
6. Explain working of collections.deque in Python with
examples.
Answer: collections.deque provides O(1) time for append and pop operations on
both ends. Example:
from collections import deque
q = deque()
q.append('A')
q.appendleft('B')
q.pop()
q.popleft(). It’s efficient and ideal for queues and stacks.
7. Compare and contrast queue, circular queue, and deque.
Answer: Queue allows insertion at rear and deletion at front (FIFO). Circular
queue reuses freed spaces by connecting ends. Deque allows insertion/deletion
at both ends (double-ended queue). Deque offers maximum flexibility.
8. Describe how overflow and underflow are managed in
circular queues.
Answer: Overflow occurs when (rear+1)%size == front. Underflow occurs when
front == -1. Both conditions are handled before performing enqueue/dequeue to
avoid errors.
9. Explain the conversion of infix to postfix using stack
concept.
Answer: Operators and operands are processed left to right. Operands directly
added to output, operators pushed to stack based on precedence. When closing
parenthesis or lower precedence operator is found, operators are popped and
added to output.
10. Discuss differences between stack, queue, and deque.
Answer: Stack follows LIFO, queue follows FIFO, deque supports both. Stack uses
push/pop, queue uses enqueue/dequeue, deque uses append/appendleft and
pop/popleft. Deque is most versatile among all.
[NOTE: Kindly cross check answers once from other source also, Quantity and Quality of answers also kindly check before use]
Comments
Post a Comment