TEZPUR 2025 — Computer PYQ
TEZPUR | Computer | 2025which of the following is an advantage of using a stack over a queue?
Choose the correct answer:
- A.
It allows for FIFO (First-In-First-Out) operations
- B.
It allows for LIFO (Last-In-First-Out) operations, useful in recursive algorithms
(Correct Answer) - C.
It allows random access to elements
- D.
It supports efficient enqueue and dequeue operations from both ends
It allows for LIFO (Last-In-First-Out) operations, useful in recursive algorithms
Explanation
The correct answer is (b) It allows for LIFO (Last-In-First-Out) operations, useful in recursive algorithms.
A stack and a queue are both linear data structures, but they operate on fundamentally different principles:
Stack (LIFO): The last element added to the stack is the first one to be removed. This behavior is ideal for implementing function calls, undo mechanisms, and recursive algorithms where the most recent state must be processed first.
Queue (FIFO): The first element added is the first one to be removed. This is used for task scheduling, buffering, and bread-first search algorithms.
We can define the operational differences mathematically using the sequence of operations:
StackLIFO:Push(x)→Pop()⟹x
QueueFIFO:Enqueue(x)→Dequeue()⟹x
In a recursive function call, the system uses a stack to manage the execution context. If we have a sequence of function calls f1,f2,…,fn, the stack ensures that fn is completed before returning to fn−1, which is necessary for recursive integrity:
Statecurrent=Top(Stack)
