Data Structures · Visualization
Deque: Push Back
Deque
Pushing to the back adds a new item after the current last item, making it the new back — the same behaviour as enqueueing in a plain queue. Time: O(1). Space: O(1) per operation.
Big-O: Push/pop at both ends in O(1).
Deque: Push Back
DequePushing to the back adds a new item after the current last item, making it the new back — the same behaviour as enqueueing in a plain queue. The visualizer's default deque is empty and its default value is 15, so the first pushBack writes 15 into the single slot and the deque reads [15]; a second call would give [15, 15]. A linked deque links one node at the tail, and a circular array writes at index back and increments modulo capacity, so the cost is O(1) and independent of how many items are already stored.
How Push Back Works
- Take the new value to add — the visualizer uses 15.
- Check capacity so a fixed-size ring buffer never overwrites the front.
- Place it after the current back item, at index back modulo capacity.
- Update the 'back' reference to point to this new item.
- If the deque was empty, the front reference now names the same item.
Push Back Worked Example
Input: pushBack(15) on the default empty deque
- The default deque holds no items, so 15 fills the only slot.
- Result: [15], with 15 served as both front and back.
- Pushing 15 once more appends after it: [15, 15].
Output: [15]
Press ▶ Run to watch it step by step.
from collections import deque
d = deque()
d.append(1) # push back
d.appendleft(2) # push front
d.pop() # pop back
d.popleft() # pop front
# O(1) at both ends
# example: push back 15 on [1, 2, 3]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.
Push Back Time & Space Complexity
When to Use Push Back
- Adding new items to the end of a work queue as usual
- Growing a sliding window by including the newest element
- Appending steps to a history log
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.