Imagine a stack is used to track function calls in a recursive program. What happens to the stack when a function returns?
The stack remains unchanged.
The corresponding function call is popped from the stack.
The corresponding function call is pushed onto the stack.
The entire stack is cleared.
Which real-life scenario most accurately reflects the LIFO (Last In First Out) principle of a stack data structure?
A list of tasks sorted by priority.
A queue of people waiting for a bus.
A tree of files and folders on a computer.
A stack of plates on a table.
How are stacks utilized in syntax parsing within compilers?
To generate intermediate code during compilation.
For performing code optimization.
For storing the symbol table of variables.
To check for matching parentheses, braces, and brackets.
How do stacks facilitate backtracking in algorithms?
By optimizing the search space for the algorithm.
By storing the optimal solution found so far.
By providing a mechanism for parallel processing.
By maintaining a record of visited states and enabling the algorithm to revert to previous states.
Consider the scenario of undoing actions in a text editor. Which data structure would be most suitable for implementing an 'undo' feature?
Binary Tree
Linked List
Queue
Stack
In maze-solving algorithms, how does the use of a stack differ between depth-first search (DFS) and breadth-first search (BFS)?
DFS uses a stack only if the maze is solvable, while BFS always uses a queue.
Both DFS and BFS use stacks identically; the difference lies in how they mark visited nodes.
DFS uses a stack to explore as deeply as possible before backtracking, while BFS uses a queue to explore all neighbors at a given level.
BFS uses a stack to prioritize unexplored paths, while DFS uses a queue to systematically explore all directions.
What is the time complexity of the 'peek' operation in a well-implemented stack?
O(n)
O(n log n)
O(1)
O(log n)
Which of the following operations is NOT typically associated with a Deque?
push (insert at the rear)
pop (remove from the rear)
peek (view the element at the front without removing)
inject (insert at the front)
In postfix evaluation, what action is taken when an operand is encountered?
It is immediately evaluated.
It is ignored.
It triggers the evaluation of operators on the stack.
It is pushed onto the stack.
You need to implement a stack that can store a large number of items and the maximum number of items is unknown. Which implementation would be more suitable?
Stack using a singly linked list
Stack using a dynamic array
Stack using a fixed-size array
Stack using a doubly linked list