AlgoScope

Deque

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

Data structures, data structure, beginnerAlso called double-ended queue
pop-back removes 3 from the back. 2 items remain.95frontrearfrontback

Deque: Push and pop at both ends

Decision, step 5 of 10

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

Cost

Push front
O(1)
Push back
O(1)
Pop front
O(1)
Pop back
O(1)
Space
O(n)

Before this

Leads to

Topics that need this one first.