Which of these is NOT a typical application of stacks?
Storing data in a priority-based order
Undo/Redo functionality in text editors
Managing function calls in a program's execution
Evaluating mathematical expressions (postfix notation)
If you implement a stack using a dynamically allocated array, what is the time complexity of pushing an element in the worst-case scenario if you need to resize the array?
O(n)
O(log n)
O(n log n)
O(1)
What is the primary disadvantage of using stacks compared to other data structures?
Slow insertion and deletion at the end
High memory consumption
Limited access to elements (only top)
Inability to store duplicate elements
How does a stack help in converting infix expressions to postfix?
By reversing the order of operands
By prioritizing operators based on precedence
By eliminating the need for parentheses
By directly translating the expression
In the context of the 'Next Greater Element' problem, what does the term 'next greater' refer to?
The element with the next highest value in a sorted order.
The element that appears most frequently after the current element.
The element that is both to the right and has a larger value.
The element that is lexicographically greater.
In which scenario would an array-based stack be a more suitable choice than a linked list-based stack?
When the maximum size of the stack is unknown.
When dealing with a very large dataset where memory usage is critical.
When frequent insertions and deletions are required in the middle of the stack.
When the stack size is known in advance and relatively small.
In depth-first search (DFS) algorithms, what role does the stack play?
Calculating shortest paths
Storing visited nodes
Storing edge weights
Maintaining the order of node exploration
What is the primary advantage of using a linked list to implement a stack over an array?
Simpler implementation
Faster push and pop operations
Lower memory usage
Dynamic resizing capability
What value does the 'peek' operation return if the stack is empty?
-1
null
It depends on the implementation.
0
What is the space complexity of a stack that stores n integers?
O(n^2)