Data Structures · Visualization

Deque: Pop Front

Deque

Popping from the front removes and returns the current first item, shrinking the deque from that end — the same as dequeueing a plain queue. Time: O(1). Space: O(1) per operation.

Big-O: Push/pop at both ends in O(1).

Deque: Pop Front

Deque

Popping from the front removes and returns the current first item, shrinking the deque from that end — the same as dequeueing a plain queue. The visualizer's default deque is empty, so popFront() on a fresh page reports 'Deque is empty — nothing to pop' instead of removing anything; after a pushBack(15) the front is 15 and popFront() removes it, leaving []. With the front index advanced modulo capacity, the operation is O(1) and never shifts the remaining items.

How Pop Front Works

  1. Check that the deque is not empty — an empty deque must report that there is nothing to pop.
  2. Read the value at the front, which is 15 after a pushBack(15) on the default empty deque.
  3. Advance the front index past that item, or unlink the front node.
  4. Return the removed value; if it was the last item, front and back both become empty.

Pop Front Worked Example

Input: popFront() on the default deque

  1. The default deque is empty, so the first frame says 'Deque is empty — nothing to pop'.
  2. After pushBack(15) the deque is [15]; popFront() now returns 15.
  3. The deque is empty again — front and back both point at nothing.

Output: Removed: 15, remaining deque: []

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: pop front on [1, 2, 3]
Input: popFront() on the default 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.

Pop Front Time & Space Complexity

TimeO(1)
SpaceO(1) per operation

When to Use Pop Front

  • Serving the next task from the front of a work queue
  • Removing outdated elements from the front of a sliding window
  • Implementing 'redo' by taking the next state from the front

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.