What is the difference between a stack and a queue, and when would you choose one over the other?
technical-conceptual · Junior level · software-engineering
What the interviewer is really asking
Assesses foundational knowledge of data structures and ability to match the right tool to a problem.
What to say
- Explain LIFO (stack) vs FIFO (queue) with simple concrete analogies — a call stack vs a print queue.
- Give a real use case for each: stack for undo/redo or DFS traversal, queue for BFS or task scheduling.
- Mention that both have O(1) push/pop or enqueue/dequeue in typical implementations.
What to avoid
- Confuse the two or say one is strictly 'better' without context.
- Only describe them abstractly without linking to a real use case.
- Claim stacks are arrays and queues are linked lists as if that's a hard rule.
Example answers
Strong: A stack is perfect for tracking browser history — the back button pops the most recent page. A queue works well for processing incoming web requests in the order they arrived.
Weak: A stack is FIFO, right? Or maybe that's a queue — I'd need to look it up before using one in code.
Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.