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
How Does It Work?
Everything enters at the rear and leaves at the front. Watch the two pointers across this sequence on an initially empty queue — rear only ever moves right as items arrive, and front only ever moves right as items leave. Neither can go backwards, and that is what enforces FIFO:
- enqueue(10): [10]
- enqueue(20): [10, 20]
- enqueue(30): [10, 20, 30]
- dequeue(): Returns 10 → [20, 30]
- peek(): Returns 20 → [20, 30] (unchanged)
Notice that 10 was the first in and the first out, while peek read the new front without changing the size. No operation ever touches the middle of the queue, which is why each one costs the same regardless of how many items are waiting.
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)
Every operation works on a pointer rather than the contents, so the cost is flat — the line stays level no matter how large the queue grows:
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
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.