Previous Year Questions & Answers –
Queue
1. Define a queue. How is it different from a stack?
➢ A queue is a linear data structure that follows FIFO (First In First Out)
principle. The element inserted first is removed first.
A stack follows LIFO (Last In First Out), where the last inserted element is
removed first.
2. Write the algorithm for enqueue() and dequeue() operations.
Enqueue(x):
arduino
CopyEdit
if rear == size - 1:
print "Queue Overflow"
else:
rear = rear + 1
queue[rear] = x
Dequeue():
arduino
CopyEdit
if front > rear:
print "Queue Underflow"
else:
x = queue[front]
front = front + 1
return x
, 3. Applications of Queue:
• CPU scheduling
• Printer spooler
• BFS in graphs
• Customer service systems
• Data buffering
4. What is a circular queue? Why is it used?
A circular queue connects the last position to the first.
It avoids the problem of "false overflow" in linear queues and uses memory efficiently
by wrapping around.
5. Overflow and Underflow in Queue:
Answer:
• Overflow: When the queue is full and cannot insert more elements.
• Underflow: When the queue is empty and we try to remove elements.
6. Difference Between peek() and dequeue():
Answer:
• peek() returns the front element without removing it.
• dequeue() removes the front element from the queue.
7. Queue Using Array (Python Example):
queue = []
# Enqueue
queue.append(10)
Queue
1. Define a queue. How is it different from a stack?
➢ A queue is a linear data structure that follows FIFO (First In First Out)
principle. The element inserted first is removed first.
A stack follows LIFO (Last In First Out), where the last inserted element is
removed first.
2. Write the algorithm for enqueue() and dequeue() operations.
Enqueue(x):
arduino
CopyEdit
if rear == size - 1:
print "Queue Overflow"
else:
rear = rear + 1
queue[rear] = x
Dequeue():
arduino
CopyEdit
if front > rear:
print "Queue Underflow"
else:
x = queue[front]
front = front + 1
return x
, 3. Applications of Queue:
• CPU scheduling
• Printer spooler
• BFS in graphs
• Customer service systems
• Data buffering
4. What is a circular queue? Why is it used?
A circular queue connects the last position to the first.
It avoids the problem of "false overflow" in linear queues and uses memory efficiently
by wrapping around.
5. Overflow and Underflow in Queue:
Answer:
• Overflow: When the queue is full and cannot insert more elements.
• Underflow: When the queue is empty and we try to remove elements.
6. Difference Between peek() and dequeue():
Answer:
• peek() returns the front element without removing it.
• dequeue() removes the front element from the queue.
7. Queue Using Array (Python Example):
queue = []
# Enqueue
queue.append(10)