Queue
Tripura Board · Class 12 · Computer Science
NCERT Solutions for Queue — Tripura Board Class 12 Computer Science.
Interactive on Super Tutor
Studying Queue? Get the full interactive chapter.
Quizzes, flashcards, AI doubt-solver and a step-by-step study plan — built for ncert solutions and more.
1,000+ Class 12 students started this chapter today

This is just one of 6+ visuals inside Super Tutor's Queue chapter
Explore the full setEXERCISE — Chapter 4: Queue
1aFill in the blank: _______________ is a linear list of elements in which insertion and deletion takes place from different ends.Show solution
Explanation: A Queue is a linear data structure in which insertion takes place at one end (called the Rear) and deletion takes place at the other end (called the Front). Because insertion and deletion happen at different ends, it follows the FIFO (First In First Out) principle.
1bFill in the blank: Operations on a queue are performed in _______________ order.Show solution
Explanation: In a queue, the element that is inserted first is the one that gets deleted first. This ordering is called FIFO — First In, First Out. For example, if A, B, C are inserted in that order, A will be the first one to be deleted.
1cFill in the blank: Insertion operation in a queue is called _______________ and deletion operation in a queue is called _______________.Show solution
Explanation:
- enqueue: adds a new element at the Rear end of the queue.
- dequeue: removes an element from the Front end of the queue.
1dFill in the blank: Deletion of elements is performed from _______________ end of the queue.Show solution
Explanation: In a queue, following the FIFO strategy, deletion (dequeue operation) always happens from the Front end, while insertion (enqueue) happens at the Rear end.
1eFill in the blank: Elements 'A', 'S', 'D' and 'F' are present in the queue, and they are deleted one at a time, _______________ is the sequence of element received.Show solution
Explanation: A queue follows FIFO order. The elements are present as:
When deleted one at a time from the Front, the sequence received is: A → S → D → F.
1fFill in the blank: _______________ is a data structure where elements can be added or removed at either end, but not in the middle.Show solution
Explanation: A Deque (Double-Ended Queue) allows insertion and deletion at both the Front and the Rear ends. However, no insertion or deletion is allowed in the middle. It is a generalised version of both stack and queue.
1gFill in the blank: A deque contains 'z', 'x', 'c', 'v' and 'b'. Elements received after deletion are 'z', 'b', 'v', 'x' and 'c'. _______________ is the sequence of deletion operation performed on deque.Show solution
Explanation:
Initial deque (Front → Rear):
| Step | Operation | Element Removed | Deque Status |
|------|-----------|----------------|--------------|
| 1 | deletionFront() | z | x, c, v, b |
| 2 | deletionRear() | b | x, c, v |
| 3 | deletionRear() | v | x, c |
| 4 | deletionRear() | x | c |
| 5 | deletionFront() | c | (empty) |
Sequence of operations: deletionFront, deletionRear, deletionRear, deletionRear, deletionFront
2Compare and contrast queue with stack.Show solution
Comparison (Similarities):
- Both are linear data structures.
- Both are ordered collections of elements.
- Both support insertion and deletion operations.
- Both can be implemented using Python lists.
Contrast (Differences):
| Feature | Stack | Queue |
|---------|-------|-------|
| Principle | LIFO (Last In First Out) | FIFO (First In First Out) |
| Insertion end | Top | Rear |
| Deletion end | Top (same as insertion) | Front (opposite to insertion) |
| Insertion operation | push() | enqueue() |
| Deletion operation | pop() | dequeue() |
| Pointers used | One pointer: Top | Two pointers: Front and Rear |
| Example | Undo operation in editor | Printer job scheduling |
| Python implementation | `append()` to insert, `pop()` to delete | `append()` to insert, `pop(0)` to delete |
Conclusion: Both are useful data structures but differ in the order in which elements are accessed. Stack works on LIFO while Queue works on FIFO principle.
3How does FIFO describe queue?Show solution
FIFO describes the fundamental behaviour of a queue:
- The element that is inserted first (at the Rear) is the element that is deleted first (from the Front).
- In other words, elements leave the queue in the same order in which they entered.
Real-life analogy: Consider a queue of people waiting at a ticket counter. The person who joins the queue first gets the ticket first and leaves first. No one can jump the queue from the middle.
Example:
Suppose we perform the following operations:
Queue status:
Now performing dequeue operations:
- dequeue() → returns 10 (first inserted, first removed)
- dequeue() → returns 20
- dequeue() → returns 30
This confirms the FIFO property: the order of deletion is the same as the order of insertion.
4Write a menu driven python program using queue, to implement movement of shuttlecock in its box.Show solution
Python Program:
```python
# Queue implementation for shuttlecock box
def enqueue(myQueue, element):
"""Insert shuttlecock into the box (at Rear)"""
myQueue.append(element)
print(f"Shuttlecock '{element}' added to the box.")
def dequeue(myQueue):
"""Remove shuttlecock from the box (from Front)"""
if not isEmpty(myQueue):
removed = myQueue.pop(0)
print(f"Shuttlecock '{removed}' taken out from the box.")
return removed
else:
print("Box is empty! No shuttlecock to remove.")
return None
def isEmpty(myQueue):
"""Check if box is empty"""
return len(myQueue) == 0
def peek(myQueue):
"""View the shuttlecock at the front without removing"""
if isEmpty(myQueue):
print("Box is empty!")
return None
else:
print(f"Shuttlecock at the front of box: '{myQueue[0]}'")
return myQueue[0]
def size(myQueue):
"""Display number of shuttlecocks in box"""
print(f"Number of shuttlecocks in box: {len(myQueue)}")
return len(myQueue)
def displayBox(myQueue):
"""Display all shuttlecocks in the box"""
if isEmpty(myQueue):
print("Box is empty!")
else:
print("Shuttlecocks in box (Front to Rear):", myQueue)
# Main menu-driven program
def main():
shuttlecockBox = list()
while True:
print("\n===== SHUTTLECOCK BOX MENU =====")
print("1. Add shuttlecock to box (enqueue)")
print("2. Take shuttlecock from box (dequeue)")
print("3. View front shuttlecock (peek)")
print("4. Check if box is empty")
print("5. Count shuttlecocks in box")
print("6. Display all shuttlecocks")
print("7. Exit")
choice = int(input("Enter your choice (1-7): "))
if choice == 1:
name = input("Enter shuttlecock name/number to add: ")
enqueue(shuttlecockBox, name)
elif choice == 2:
dequeue(shuttlecockBox)
elif choice == 3:
peek(shuttlecockBox)
elif choice == 4:
if isEmpty(shuttlecockBox):
print("Box is EMPTY.")
else:
print("Box is NOT empty.")
elif choice == 5:
size(shuttlecockBox)
elif choice == 6:
displayBox(shuttlecockBox)
elif choice == 7:
print("Exiting program.")
break
else:
print("Invalid choice! Please enter between 1 and 7.")
main()
```
Sample Output:
```
===== SHUTTLECOCK BOX MENU =====
1. Add shuttlecock to box (enqueue)
...
Enter your choice: 1
Enter shuttlecock name/number to add: SC1
Shuttlecock 'SC1' added to the box.
Enter your choice: 1
Enter shuttlecock name/number to add: SC2
Shuttlecock 'SC2' added to the box.
Enter your choice: 2
Shuttlecock 'SC1' taken out from the box.
```
Explanation: The shuttlecock added first (SC1) is taken out first, demonstrating FIFO behaviour of a queue.
5How is queue data type different from deque data type?Show solution
| Feature | Queue | Deque (Double-Ended Queue) |
|---------|-------|----------------------------|
| Full form | Queue | Double-Ended Queue |
| Insertion | Only at Rear end | At both Front and Rear ends |
| Deletion | Only at Front end | At both Front and Rear ends |
| Principle | Strictly FIFO | Can behave as FIFO or LIFO |
| Flexibility | Less flexible | More flexible |
| Operations | enqueue, dequeue, peek, isEmpty | insertFront, insertRear, deletionFront, deletionRear, getFront, getRear, isEmpty |
| Stack simulation | Cannot simulate a stack | Can simulate both stack and queue |
| Example use | Printer job queue, CPU scheduling | Browser history (back and forward), Undo-Redo operations |
Key Point: A queue is a restricted version of deque. In a queue, insertion is only at Rear and deletion only at Front. A deque generalises this by allowing both operations at both ends, making it more versatile.
6Show the status of queue after each operation: enqueue(34), enqueue(54), dequeue(), enqueue(12), dequeue(), enqueue(), dequeue(), dequeue(), enqueue(1)Show solution
Initial Queue: Empty
Concept: Queue follows FIFO. Insertion at Rear using `enqueue()`, deletion from Front using `dequeue()`.
| Step | Operation | Action | Queue Status (Front → Rear) |
|------|-----------|--------|-----------------------------|
| 0 | — | Initial state | (Empty) |
| 1 | enqueue(34) | Insert 34 at Rear | |
| 2 | enqueue(54) | Insert 54 at Rear | |
| 3 | dequeue() | Remove 34 from Front | |
| 4 | enqueue(12) | Insert 12 at Rear | |
| 5 | dequeue() | Remove 54 from Front | |
| 6 | enqueue() | Invalid — no element given; Queue unchanged | |
| 7 | dequeue() | Remove 12 from Front | (Empty) |
| 8 | dequeue() | Queue is empty — Underflow / Queue Empty message | (Empty) |
| 9 | enqueue(1) | Insert 1 at Rear | |
Final Queue Status: with Front → 1 ← Rear
7Show the status of deque after each operation: peek(), insertFront(12), insertRear(67), deletionFront(), insertRear(43), deletionRear(), deletionFront(), deletionRear()Show solution
Concept: A Deque (Double-Ended Queue) allows insertion and deletion at both Front and Rear ends.
| Step | Operation | Action | Deque Status (Front → Rear) |
|------|-----------|--------|-----------------------------|
| 0 | — | Initial state | (Empty) |
| 1 | peek() | Deque is empty — returns None / prints "Deque is empty" | (Empty) |
| 2 | insertFront(12) | Insert 12 at Front | |
| 3 | insertRear(67) | Insert 67 at Rear | |
| 4 | deletionFront() | Remove 12 from Front → returns 12 | |
| 5 | insertRear(43) | Insert 43 at Rear | |
| 6 | deletionRear() | Remove 43 from Rear → returns 43 | |
| 7 | deletionFront() | Remove 67 from Front → returns 67 | (Empty) |
| 8 | deletionRear() | Deque is empty — Underflow / prints "Queue underflow" | (Empty) |
Final Deque Status: Empty
8Write a python program to check whether the given string is palindrome or not, using deque.Show solution
Algorithm using Deque:
1. Insert all characters of the string into a deque.
2. Repeatedly remove one character from the Front and one from the Rear.
3. Compare the two characters.
4. If they are equal for all pairs, the string is a palindrome.
5. If any pair is unequal, it is not a palindrome.
Python Program:
```python
# Palindrome check using Deque
def insertRear(myDeque, element):
"""Insert element at Rear of deque"""
myDeque.append(element)
def deletionFront(myDeque):
"""Delete element from Front of deque"""
if not isEmpty(myDeque):
return myDeque.pop(0)
else:
print("Deque underflow")
return None
def deletionRear(myDeque):
"""Delete element from Rear of deque"""
if not isEmpty(myDeque):
return myDeque.pop()
else:
print("Deque underflow")
return None
def isEmpty(myDeque):
"""Check if deque is empty"""
return len(myDeque) == 0
def size(myDeque):
"""Return size of deque"""
return len(myDeque)
def isPalindrome(inputString):
"""Check if inputString is palindrome using deque"""
myDeque = list()
# Step 1: Insert all characters into deque
for char in inputString:
insertRear(myDeque, char)
# Step 2: Compare front and rear characters
isPalin = True
while size(myDeque) > 1:
frontChar = deletionFront(myDeque) # remove from front
rearChar = deletionRear(myDeque) # remove from rear
if frontChar != rearChar:
isPalin = False
break
return isPalin
# Main program
def main():
inputStr = input("Enter a string to check for palindrome: ")
# Convert to lowercase for case-insensitive comparison
inputStr = inputStr.lower()
if isPalindrome(inputStr):
print(f"'{inputStr}' is a PALINDROME.")
else:
print(f"'{inputStr}' is NOT a palindrome.")
main()
```
Sample Output 1:
```
Enter a string to check for palindrome: madam
'madam' is a PALINDROME.
```
Sample Output 2:
```
Enter a string to check for palindrome: hello
'hello' is NOT a palindrome.
```
Sample Output 3:
```
Enter a string to check for palindrome: racecar
'racecar' is a PALINDROME.
```
Dry Run for 'madam':
| Step | Deque | Front Char | Rear Char | Equal? |
|------|-------|-----------|----------|--------|
| Initial | [m, a, d, a, m] | — | — | — |
| 1 | [a, d, a] | m | m | Yes |
| 2 | [d] | a | a | Yes |
| 3 | [d] | size=1, loop ends | — | — |
Result: Palindrome ✓
Stuck on a step?
Ask Super Tutor AI to explain any solution on this page in a simpler way — free, 24x7.
Ask a Doubt FreeFrequently Asked Questions
What are the important topics in Queue for Tripura Board Class 12 Computer Science?
How to score full marks in Queue — Tripura Board Class 12 Computer Science?
Where can I get free NCERT Solutions for Queue Class 12 Computer Science?
Sources & Official References
Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.
More resources for Queue
Important Questions
Practice with board exam-style questions
Syllabus
What topics to cover
Revision Notes
Key points for last-minute revision
Study Plan
Step-by-step plan to ace this chapter
Flashcards
Quick-fire cards for active recall
Formula Sheet
All formulas in one place
Chapter Summary
Understand the chapter at a glance
Practice Quiz
Test yourself with a quick quiz
Concept Maps
See how topics connect visually
For serious students
Get the full Queue chapter — for free.
Quizzes, flashcards, AI doubt-solver and a step-by-step study plan for Tripura Board Class 12 Computer Science.