Past exam question: 2066 Bhadra (Regular / Back), Q3(b)
Open in the Padhaiko appQuestion
Explain the advantages of dynamic implementation of stack and queue over sequential storage to represent stack and queue.
Solution
Advantages of Dynamic (Linked) Stack & Queue over Sequential (Array) Storage:
- No Fixed Capacity / No False Overflow: Size grows and shrinks dynamically at runtime via
malloc/free, avoiding compile-timeMAXlimits and linear-queue false overflow. - Zero Unused Memory Wastage: Memory is allocated strictly for currently stored items rather than reserving a worst-case fixed array.
- Flexible Non-Contiguous Storage: Nodes can reside in scattered heap locations instead of requiring one large contiguous block.
Answer:
Dynamic linked implementations of stacks and queues eliminate fixed MAX overflow, avoid pre-allocating unused array space, and use scattered heap memory instead of large contiguous blocks.