skip to content

questions

5

Why can a linked-node stack hold millions of elements when a thread's call stack overflows far sooner?

level: middleimportance: must knowfreq 62%

basics

~20 s

They are different things. A stack data structure is a LIFO discipline over memory you allocate on demand, so its ceiling is available memory. A thread's call stack is one fixed contiguous region reserved when the thread starts.

open as a page

In an array-backed stack, what changes in push, pop and the empty check if `top` means the next free slot?

level: middleimportance: should knowfreq 52%

basics

~20 s

Two conventions exist: top indexes the last element (empty is top == -1, push increments then writes), or top indexes the next free slot (empty is top == 0, push writes then increments). Pick one and check every operation against it.

open as a page

What should pop on an empty stack do — signal an error, or return a sentinel value like -1?

level: seniorimportance: should knowfreq 45%

basics

~20 s

Signal the failure out of band. A sentinel is safe only when it lies outside the element domain, and for signed sensor readings -1 is a legal reading, so the caller cannot tell emptiness from data and the corruption is silent.

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