Coding & data structures · Linear structures — lists, stacks, queues, and intervals

Stacks and queues: deferring a decision

A stack is not a container, it is a policy — "I can't decide about this item yet, so hold it until I can" — and once you read it that way, parentheses, expression evaluation, undo, and recursion are all one problem; queues are the mirror image, with one trap that costs real interviews, because the obvious array implementation of a queue is quadratic.

24 min read Full lesson in the app Patterns: stack of deferred work, auxiliary stack, circular buffer, amortised analysis, explicit stack over recursion

What you'll be able to do

Log in to read the rest of this lesson

A stack is not a container, it is a policy — "I can't decide about this item yet, so hold it until I can" — and once you read it that way, parentheses, expression evaluation, undo, and recursion are all one problem; queues are the mirror image, with one trap that costs real interviews, because the obvious array implementation of a queue is quadratic. This walkthrough runs about 24 minutes, with runnable code you can edit and re-run as you read. A new account gets 7 days of Pro free, no card required.

Log in to continue

The first module of every track is free to read on the web: see what's open in Coding & data structures.