Level 1: Bronze
A memorized definition. Not wrong, but it stops there.
A stack is LIFO and a queue is FIFO.
3 stars If you are short on time, start with this one.
In one or two sentences
A stack is last in, first out. A queue is first in, first out.
Say it out loud, or type it below. What you type never leaves this device.
A memorized definition. Not wrong, but it stops there.
A stack is LIFO and a queue is FIFO.
Correct, but too broad or missing context.
Stacks are used for function calls, undo and bracket matching. Queues are used for job waiting lines and breadth first search.
Reaches principle, use and trade-off, with words that invite the next question.
A stack pushes and pops at one end only, and the call stack that stores function calls is the classic example. Deep recursion can overflow it, so it is sometimes rewritten with a loop and an explicit stack. A queue fits ordered processing, message queues and breadth first search. Building a queue on a plain array makes removal from the front costly, so use a circular buffer or a linked list. A deque pushes and pops at both ends and covers both.
These are likely next questions from an interviewer. Think of your answer first, then press the button.
1 / 3
Can you build a queue from two stacks?
Keep an input stack and an output stack, and move everything across when the output is empty. Each element moves once, so it is O(1) on average.
2 / 3
Why does a stack overflow happen?
Recursion does not end or goes too deep and exceeds the call stack limit. Check the base case or switch to a loop.
3 / 3
How does a priority queue differ from a normal queue?
Elements leave by priority, not arrival order. It is usually implemented with a heap.
This is a textbook level concept, so no outside source is listed.