Guided Notes

Stacks & Queues

LIFO stacks and FIFO queues, their operations, implementations, and real-world uses.

Stacks: last in, first out

Slide 1 / 5

A stack is like a pile of plates: you add and remove only at the top. The last item added is the first removed (LIFO).

Operations — all O(1): • push — add to the top. • pop — remove from the top. • peek — look at the top without removing it. • is_empty / size.

In Python, a list works as a stack: append() pushes, pop() pops, stack[-1] peeks.

← Linked Lists