What key advantage does a Deque (Double-ended Queue) offer over a Stack?
Deque allows deletions only at one end.
Deque is more memory-efficient than a Stack.
Deque allows insertions and deletions at both ends.
Deque allows insertions only at one end.
In a stack implemented using a singly linked list, which end of the list typically represents the top of the stack?
Middle
Tail
Head
It can be either the head or the tail, depending on the implementation.
How do stacks facilitate backtracking in algorithms?
By providing a mechanism for parallel processing.
By storing the optimal solution found so far.
By maintaining a record of visited states and enabling the algorithm to revert to previous states.
By optimizing the search space for the algorithm.
What is the time complexity of the 'peek' operation in a well-implemented stack?
O(n log n)
O(1)
O(n)
O(log n)
In the context of expression parsing, what role does a stack play?
Generating machine code from the expression.
Evaluating the parsed expression directly.
Optimizing the expression for better performance.
Storing the lexical tokens identified in the expression.
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 to explore as deeply as possible before backtracking, while BFS uses a queue to explore all neighbors at a given level.
Both DFS and BFS use stacks identically; the difference lies in how they mark visited nodes.
DFS uses a stack only if the maze is solvable, while BFS always uses a queue.
BFS uses a stack to prioritize unexplored paths, while DFS uses a queue to systematically explore all directions.
Consider the scenario of undoing actions in a text editor. Which data structure would be most suitable for implementing an 'undo' feature?
Stack
Queue
Binary Tree
Linked List
What is a potential drawback of using a linked list-based stack compared to an array-based stack?
Higher memory usage due to the overhead of storing pointers
Inability to handle dynamic resizing
Increased time complexity for push and pop operations
Limited stack size
How are stacks utilized in syntax parsing within compilers?
To check for matching parentheses, braces, and brackets.
To generate intermediate code during compilation.
For performing code optimization.
For storing the symbol table of variables.
Imagine a stack is used to track function calls in a recursive program. What happens to the stack when a function returns?
The corresponding function call is popped from the stack.
The stack remains unchanged.
The entire stack is cleared.
The corresponding function call is pushed onto the stack.