AlgoScope

Deque

Data structurebeginnerLinear Structuresalso called double-ended queue

Insert and remove at both ends in O(1).

Decision · step 5 of 10Deque: Push and pop at both ends
95frontrearfrontback

pop-back returns 3, the item at the back. The other end is untouched. Size 2.

Open in the player →or start at step 5

What you will see

Items enter and leave from either end; used by sliding-window maximum.

How deque works →

Cost

push frontO(1)
push backO(1)
pop frontO(1)
pop backO(1)
SpaceO(n)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, try operations in any order.

Screen readers: Each element is an accessibility element with position, value and state; structural changes are announced per step.

Reduced motion: Elements appear at their destination with a crossfade; no travel longer than the element's own size.

Before this

Leads to

Topics that need this one first.