Data Structures · Visualization
Queue: Enqueue
Queue
Enqueueing adds a new item to the back of the queue, behind everyone already waiting. Time: O(1). Space: O(1) per operation.
Big-O: enqueue / dequeue are both O(1).
Queue: Enqueue
QueueEnqueueing adds a new item to the back of the queue, behind everyone already waiting. The visualizer starts from the default queue [A, B, C] — A at the front — and enqueues the default value 7, producing [A, B, C, 7] while the front stays A. Nothing shifts: a linked-list queue links one new node, and a circular buffer just advances its back index modulo capacity, so enqueue is O(1) until the buffer is full, at which point a fixed-size implementation must reject the item or overwrite the oldest one.
How Enqueue Works
- Take the new value to add — the visualizer uses 7.
- Check capacity: a bounded circular queue reports 'full' instead of overwriting the front silently.
- Place it at the back, immediately after the current last item (C in the default queue).
- Update the 'back' reference to the new item, or advance it modulo capacity.
- Leave the front pointer alone — the order of everyone already waiting is unchanged.
Enqueue Worked Example
Input: enqueue(7) on the default queue [A, B, C]
- Current queue, front on the left: [A, B, C] — A is next to be served.
- 7 joins at the back: [A, B, C, 7].
- The front is still A, so three dequeues are needed before 7 reaches the front.
Output: [A, B, C, 7] with A still at the front
Press ▶ Run to watch it step by step.
from collections import deque
q = deque([1])
q.append(2) # enqueue at the back
print(q) # deque([1, 2])
# example: qpush 7 on [3, 5]Behind the Scenes Execution
Press ▶ Run in the visualizer — the call stack, registers and memory will replay here in sync with the code, line by line.
Enqueue Time & Space Complexity
When to Use Enqueue
- Adding a new customer to the back of a service line
- Submitting a new print job to the printer queue
- Adding a newly discovered node to the BFS frontier
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Ready for the next step?
See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.