What value does the 'peek' operation return if the stack is empty?
It depends on the implementation.
0
null
-1
In the context of the 'Next Greater Element' problem, what does the term 'next greater' refer to?
The element that appears most frequently after the current element.
The element with the next highest value in a sorted order.
The element that is lexicographically greater.
The element that is both to the right and has a larger value.
Which data structure is most closely related to the concept of recursion?
Stack
Linked List
Queue
Tree
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
How does a stack help in implementing the undo functionality in text editors?
By using a linked list of characters.
By storing a stack of states.
By hashing the content.
By storing a queue of actions.
In a 'Next Greater Element' problem, if no greater element exists to the right of an element, what is typically assigned as its 'next greater element'?
None of the above
The element itself
Which of the following is a significant drawback of implementing a stack using a static array?
Complex implementation
Slow push and pop operations
High memory usage
Fixed size limitation
What is the space complexity of a stack that stores n integers?
O(1)
O(log n)
O(n^2)
O(n)
How do stacks and heaps differ in terms of element ordering?
Stack follows FIFO order, while heap has no specific order
Stack has no specific order, while heap maintains elements in sorted order
Both stack and heap maintain elements in sorted order, but with different sorting algorithms
Stack follows LIFO order, while heap maintains a partial ordering
In which scenario would an array-based stack be a more suitable choice than a linked list-based stack?
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 maximum size of the stack is unknown.
When the stack size is known in advance and relatively small.