← Lab

📚 Stack — LIFO, one end, O(1)

Everything happens at the top: push, pop, peek — all O(1). Last in, first out. This is a call stack, an undo history, DFS.

size
2
top index
1
top value
8
empty?
no
stack — grows upward, top is the only door
5
8
← top
what just happened (say it out loud)

Run an operation to see it step by step.

ė‚Žėƒ: a stack restricts access to one end, which is exactly what makes push/pop O(1) and models nested/last-in-first-out work like function calls and backtracking.
â–ķ deep-dive videos — “stack data structure LIFO explained”