A Queue is a FIFO (First-In, First-Out) linear structure where items enter at the rear pointer and exit from the front pointer.
Add items at the rear pointer position. 10 arrives first, 20 arrives second.
Front: 0, Rear: 1 | Queue: [10 (Front), 20 (Rear)]Remove and return the element at the front pointer (10) and advance front pointer.
Dequeued Value: 10 | Front: 1, Rear: 1 | Queue: [20 (Front/Rear)]People line up to buy tickets. The first person to arrive is the first person served and leaves the line first.
1 step (Constant)
O(1) Constant Time
O(N) Auxiliary Space
Memory growth rate as N expands.
Relative efficiency rating for large N.
| Operation | Time Complexity | Space Complexity |
|---|---|---|
| Enqueue | O(1) | O(1) |
| Dequeue | O(1) | O(1) |
| Front | O(1) | O(1) |
class Queue {
constructor() { this.items = []; }
enqueue(elem) { this.items.push(elem); }
dequeue() { return this.items.shift(); }
}OS process scheduling queues.
Sequences print job requests.
Level-order traversal queue buffer.
Evaluate your knowledge of FIFO mechanics, Enqueue/Dequeue pointers, ring buffers, and task scheduling.
Use queues whenever order of arrival must be strictly preserved without prioritizing newer entries!
Queue initialized. FIFO rule applies.