0
0
DSA Pythonprogramming~20 mins

Queue Concept and FIFO Principle in DSA Python - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Queue Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this queue operation sequence?
Consider a queue where we enqueue numbers 1, 2, 3 in order, then dequeue twice, then enqueue 4. What is the state of the queue?
DSA Python
queue = []
queue.append(1)  # enqueue 1
queue.append(2)  # enqueue 2
queue.append(3)  # enqueue 3
queue.pop(0)     # dequeue (removes 1)
queue.pop(0)     # dequeue (removes 2)
queue.append(4)  # enqueue 4
print(queue)
A[2, 3, 4]
B[1, 2, 3, 4]
C[4]
D[3, 4]
Attempts:
2 left
💡 Hint

Remember, queue removes from the front (first in) and adds to the back (last in).

🧠 Conceptual
intermediate
1:00remaining
Which property best describes a queue?
A queue follows which principle for adding and removing elements?
ALast In, First Out (LIFO)
BFirst In, First Out (FIFO)
CRandom Access
DLast In, Last Out (LILO)
Attempts:
2 left
💡 Hint

Think about a line of people waiting for service.

🔧 Debug
advanced
1:30remaining
What error does this queue code raise?
What error occurs when running this code snippet?
DSA Python
queue = []
queue.pop(0)  # dequeue from empty queue
AIndexError: pop from empty list
BTypeError: 'int' object is not callable
CKeyError: 0
DNo error, returns None
Attempts:
2 left
💡 Hint

What happens if you try to remove an item from an empty list by index?

🚀 Application
advanced
2:00remaining
What is the queue state after these operations?
Starting with an empty queue, perform these operations in order: enqueue 10, enqueue 20, dequeue, enqueue 30, dequeue, enqueue 40. What is the final queue?
DSA Python
queue = []
queue.append(10)  # enqueue 10
queue.append(20)  # enqueue 20
queue.pop(0)      # dequeue (removes 10)
queue.append(30)  # enqueue 30
queue.pop(0)      # dequeue (removes 20)
queue.append(40)  # enqueue 40
print(queue)
A[30, 40]
B[10, 20, 30, 40]
C[20, 30, 40]
D[40]
Attempts:
2 left
💡 Hint

Track each enqueue and dequeue step carefully.

Predict Output
expert
2:30remaining
What is the output of this queue simulation code?
This code simulates a queue with enqueue and dequeue operations. What is printed?
DSA Python
class Queue:
    def __init__(self):
        self.items = []
    def enqueue(self, item):
        self.items.append(item)
    def dequeue(self):
        if self.items:
            return self.items.pop(0)
        return None
    def __str__(self):
        return ' -> '.join(str(i) for i in self.items) + ' -> null'

q = Queue()
q.enqueue(5)
q.enqueue(10)
q.enqueue(15)
q.dequeue()
q.enqueue(20)
print(str(q))
A5 -> 10 -> 15 -> 20 -> null
B15 -> 20 -> null
C10 -> 15 -> 20 -> null
D5 -> 15 -> 20 -> null
Attempts:
2 left
💡 Hint

Remember dequeue removes the first item added.