What is the primary disadvantage of using stacks compared to other data structures?
High memory consumption
Inability to store duplicate elements
Slow insertion and deletion at the end
Limited access to elements (only top)
What happens when you try to 'pop' an element from an empty stack?
It depends on the specific implementation of the stack.
The program crashes.
A random element from the stack is removed.
A special value (like -1) is returned.
In a stack, how is the element that was added before the last added element accessed?
By searching the entire stack sequentially.
It's not possible to access elements directly in a stack.
By popping the top element first.
Directly using its index.
You are designing a system to validate arithmetic expressions. Which data structure is most suitable for checking if parentheses '(' '[' '{' are balanced in an expression?
Binary Tree
Linked List
Stack
Queue
Which of the following is a significant drawback of implementing a stack using a static array?
Fixed size limitation
Complex implementation
Slow push and pop operations
High memory usage
What is the space complexity of a stack that stores n integers?
O(1)
O(n)
O(n^2)
O(log n)
In depth-first search (DFS) algorithms, what role does the stack play?
Calculating shortest paths
Storing edge weights
Maintaining the order of node exploration
Storing visited nodes
In the context of the 'Next Greater Element' problem, what does the term 'next greater' refer to?
The element that is both to the right and has a larger value.
The element that is lexicographically greater.
The element that appears most frequently after the current element.
The element with the next highest value in a sorted order.
In the context of a dynamic array-based stack, what does amortized analysis help us determine?
The exact number of array resizes
The average time complexity of push operations over a sequence of operations
The minimum space used by the stack
The maximum time complexity of a single push operation
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 log n)