Interview concept

What are stacks and queues?

A stack removes the most recently added item first (LIFO), while a queue removes the oldest item first (FIFO). They model undo history, call stacks, traversals, and scheduling.

Interview concept

How it works

Stack operations

Push and pop at one end give LIFO order, powering recursion, expression parsing, and depth-first search.

Queue operations

Enqueue at the back and dequeue at the front give FIFO order, powering breadth-first search and buffering.

Variants

A deque allows both ends, and a priority queue orders by key rather than arrival time.

Interview concept

Responsible use

Use any live AI assistant only where interview, workplace, school, and platform rules allow it. Do not use generated answers to misrepresent your skills, experience, or authorship.

FAQ

Common questions.

What is the difference between a stack and a queue?

A stack is last-in first-out; a queue is first-in first-out. The order in which items leave is the key difference.

Where are stacks used in interviews?

In depth-first search, expression evaluation, backtracking, and the monotonic stack pattern.