AlgoScope

Stack

Only the top is reachable. The last thing down is the first thing up.

Data structures, data structure, beginnerAlso called LIFO
Empty stack with capacity 6. Running 8 operations: push 5, push 3, push 9, pop, peek, push 7, pop, pop.bottom
Empty stack with capacity 6. Running 8 operations: push 5, push 3, push 9, pop, peek, push 7, pop, pop.bottom

Stack: Push, pop, peek

Start, step 1 of 10

An empty stack. Only the TOP is ever touched, by both push and pop.

Cost

Push
O(1)
Pop
O(1)
Peek
O(1)
Search
O(n)
Space
O(n)

Before this

Leads to

Topics that need this one first.

Taught by the same lesson

Stack covers these too, in the same run.