skip to content

Stacks & Queues

Stacks and queues are the workhorse LIFO and FIFO abstractions behind call stacks, BFS/DFS, buffers, and schedulers. Interviewers use them to test whether you can match an access discipline to a problem and reason about O(1) operation guarantees.

part ofData structures & algorithmsoverview, primer and where to startread it →
on this pageshow

questions

page 2 of 2

Should a shared ticket-intake queue be bounded, and what should enqueue report when it is full?

level: principalimportance: should knowfreq 38%

basics

~20 s

Bound it whenever arrivals are not limited by something else, because an unbounded in-memory queue converts a slow consumer into a dead process. A bounded queue must then report refusal explicitly on enqueue — never accept-and-discard — so every caller owns what happens to the rejected ticket.

open as a page

In a shared print spooler, what does round-robin across per-user queues change versus one first-in-first-out queue?

level: middleimportance: nice to knowfreq 30%

basics

~20 s

A single first-in-first-out queue is fair to jobs, not to people: one user's five-hundred-page batch delays everyone behind it. Round-robin over per-user queues makes a job's wait depend on how many users are active, not on one user's backlog.

open as a page

Which minimum-tracking stack design would you standardise on for a memory-capped device fleet, and why?

level: principalimportance: nice to knowfreq 24%

basics

~20 s

All the candidates are constant time per operation, so the decision is memory under worst-case input versus who has to maintain the clever version. Bound the stack depth first; if the simple paired-value design then fits the cap, standardise on it.

open as a page

On a memory-capped device, when a fixed-capacity stack fills, do you reject the push or grow the stack?

level: principalimportance: nice to knowfreq 28%

basics

~20 s

On memory-capped hardware, reject the push and make the rejection visible. A fixed capacity turns an unpredictable out-of-memory failure into a local, testable policy — provided the caller is told and someone has decided which readings may be lost.

open as a page

showing 31–34 of 34