Introduction
Imagine waiting in line to buy a ticket. The first person who arrives is the first to be served. This problem of managing order is what queues solve in computing, ensuring things happen in the right sequence.
Jump into concepts and practice - no test required
Think of a line at a coffee shop. Customers join the line at the back and the barista serves the customer at the front first. No one can cut in line or skip ahead.
┌─────────────┐ │ Queue │ ├─────────────┤ │ Front │ ← Dequeue removes here │ [Item A] │ │ [Item B] │ │ [Item C] │ │ Back │ ← Enqueue adds here └─────────────┘
What does a queue data structure follow?
Choose the best description.
Which of the following is the correct way to enqueue an item 5 into a queue represented as a list named q in Python?
append() adds an item to the end of the list, which matches enqueue.Given the queue q = [10, 20, 30], what will be the queue after performing q.pop(0)?
Consider this Python code snippet:
q = [] q.pop(0)
What error will occur and why?
You have a queue q = [1, 2, 3, 4]. You perform these operations:
q.append(5) q.pop(0) q.append(6) q.pop(0)
What is the final state of the queue?