What is a Single-Ended Queue?
A single-ended queue is what most people just mean when they say "queue" — insertion only happens at the rear, removal only happens at the front, and that one-directional flow is what keeps the ordering strictly first-in, first-out.
Key Characteristics
Single-ended queues have these fundamental properties:
- Two ends:
- Front (for removal) and rear (for insertion)
- Basic Operations:
- enqueue() - Add to rear
- dequeue() - Remove from front
- peek() - View front element
- isEmpty() - Check if empty
- Fixed Order:
- Elements are processed in exact arrival sequence
Visual Example
Operation sequence on an initially empty queue:
- enqueue(10): [10]
- enqueue(20): [10, 20]
- enqueue(30): [10, 20, 30]
- dequeue(): Returns 10 → [20, 30]
- peek(): Returns 20 → [20, 30] (unchanged)
Implementation Variations
Common implementation approaches:
- Array-Based:
- Fixed or dynamic array
- Need to handle wrap-around for circular queues
- Linked List:
- Head pointer as front
- Tail pointer as rear
- Efficient O(1) operations
Time Complexity
- enqueue(): O(1)
- dequeue(): O(1)
- peek(): O(1)
- isEmpty(): O(1)
Applications
Single-ended queues are used in:
- CPU task scheduling
- Print job management
- Breadth-First Search (BFS) algorithms
- Buffering data streams
- Handling requests in web servers
Comparison with Double-Ended Queue
Key differences:
- Single-ended only allows insertion at rear and removal at front
- Double-ended (deque) allows insertion/removal at both ends
- Single-ended has stricter FIFO enforcement
- Single-ended is simpler to implement
That predictability is the whole point. Plenty of algorithms and system designs depend on knowing that items get processed in exactly the order they arrived, and a single-ended queue is the simplest structure that guarantees it.