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

The rest of this lesson is in the app

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.

Continue in ChannelPulse

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