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

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. 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

  1. Take the new value to add — the visualizer uses 15.
  2. Check capacity so a fixed-size ring buffer never overwrites the front.
  3. Place it after the current back item, at index back modulo capacity.
  4. Update the 'back' reference to point to this new item.
  5. 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

  1. The default deque holds no items, so 15 fills the only slot.
  2. Result: [15], with 15 served as both front and back.
  3. Pushing 15 once more appends after it: [15, 15].

Output: [15]

Try your own input
Deque: Introduction
A "double-ended queue" — values can be added or removed from both the front and the back.
Empty deque
Active / window Result
Deque: Introduction
Press ▶ Run to watch it step by step.
Python · Deque in Code
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]
Input: pushBack(15) on the default empty deque

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

TimeO(1)
SpaceO(1) per operation

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

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits

Ready for the next step?

See the same ideas in action — visualize the algorithms that operate on these structures, or take a guided course.