Data Structures & Algorithms · Interview question

What's the difference between a stack and a queue?

A strong answer

They differ in removal order. A stack is LIFO, last in, first out: you push and pop at the same end (the top), so the most recently added item comes out first. A queue is FIFO, first in, first out: you add at the back and remove from the front, so the oldest item comes out first. Both are abstract access disciplines, not storage layouts, you can back either with an array or a linked list; what defines them is the order elements leave. The practical consequence: a stack reverses the order of what you put in, a queue preserves it. You pick based on semantics, a stack for "most recent first" (undo, call frames, backtracking), a queue for "process in arrival order" (event handling, ISR-to-main byte passing).

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Stacks & Queues

LIFO stacks and FIFO queues: the two access disciplines behind the call stack, expression evaluation, and ISR-to-main event passing, and how to back each with fixed memory.

More Stacks & Queues questions

Browse all 472 interview questions
What's the difference between a stack and a queue? | EmbeddedPrep.io