queue.definition

queue.descriptionPart1

queue.descriptionPart2

queue.keyPointsTitle

  • queue.keyPoint1
  • queue.keyPoint2
  • queue.keyPoint3
  • queue.keyPoint4

queue.exampleTitle

queue.frontLabel
10
20
30
40
queue.rearLabel
enqueue(40)queue.addedToRear

queue.syntaxTitle

// Java
Queue<Integer> queue = new LinkedList<>();
queue.offer(10);  // enqueue
int front = queue.poll();  // dequeue
# Python
from collections import deque
queue = deque()
queue.append(10)  # enqueue
front = queue.popleft()  # dequeue
// C++
#include <queue>
std::queue<int> q;
q.push(10);  // enqueue
int front = q.front(); q.pop();  // dequeue
// JavaScript
const queue = [];
queue.push(10);  // enqueue
const front = queue.shift();  // dequeue

Interactive Queue Visualization

FrontRear
0
1
2
3
4
5
6
7
↓ Enqueue
↑ Dequeue
Front:
Rear:
Size:0
Capacity:8
Status:Empty
Empty
Front
Rear
Filled
Shifting
Note: This is a linear queue with shifting. On dequeue, all elements shift left (O(n) operation). Front is always at index 0.

enhanced.realWorldExamples.title

NetflixVideo Streaming Buffer

Streaming services queue video chunks for smooth playback.

Why? FIFO ensures frames play in correct order.

Print ServersPrint Job Management

Printers queue documents in order of submission.

Why? First-come-first-served scheduling is fair and predictable.

Time Complexity

This linear queue uses an array with shifting on dequeue. While enqueue remains O(1), dequeue requires shifting all elements left, making it O(n). This trade-off keeps the front always at index 0.

OperationTimeWhy?
EnqueueO(1)Add element to rear (end of array)
DequeueO(n)Remove front element, then shift all remaining elements left
Peek / FrontO(1)View front element (index 0) without removing
isEmptyO(1)Check if queue is empty
isFullO(1)Check if queue has reached capacity
SizeO(1)Get number of elements
ClearO(n)Remove all elements
Note: Linear queues with shifting have O(n) dequeue. For O(1) dequeue, use a circular queue or linked-list implementation. Common queue use cases include CPU scheduling, print job spooling, BFS traversal, and buffering.

enhanced.complexityAnalysis.title

enhanced.complexityAnalysis.mathematicalTitle

Enqueue and dequeue are O(1) when implemented with linked list or circular array, as they only modify head/tail pointers.

🟢Best Case

O(1) for enqueue/dequeue operations in all cases.

🟡Average Case

O(1) for standard operations. Linear search for specific element is O(n).

🔴Worst Case

Array-based queues may need O(n) for resizing. Dequeue from array without circular implementation is O(n).

💾Space Complexity

O(n) for n elements stored in the queue.

enhanced.relatedTopics.prerequisites

enhanced.relatedTopics.related

enhanced.relatedTopics.advanced

Continue Learning

Test your knowledge with a quiz or explore implementation code in multiple languages.

enhanced.author.title

enhanced.author.writtenBy:enhanced.author.teamName
enhanced.author.reviewedBy:enhanced.author.reviewerName
enhanced.author.lastUpdated:January 27, 2026