What is the space complexity of a stack that stores n integers?
O(1)
O(n)
O(log n)
O(n^2)
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)
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 the stack size is known in advance and relatively small.
When frequent insertions and deletions are required in the middle of the stack.
When the maximum size of the stack is unknown.
Which data structure is most closely related to the concept of recursion?
Linked List
Stack
Queue
Tree
What happens when you try to 'pop' an element from an empty stack?
A random element from the stack is removed.
A special value (like -1) is returned.
The program crashes.
It depends on the specific implementation of the stack.
How do stacks and heaps differ in terms of element ordering?
Both stack and heap maintain elements in sorted order, but with different sorting algorithms
Stack follows FIFO order, while heap has no specific order
Stack has no specific order, while heap maintains elements in sorted order
Stack follows LIFO order, while heap maintains a partial ordering
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
What is the time complexity of pushing an element onto a stack implemented using a static array, assuming there is enough space?
In depth-first search (DFS) algorithms, what role does the stack play?
Calculating shortest paths
Maintaining the order of node exploration
Storing edge weights
Storing visited nodes
What real-world scenario accurately reflects the functioning of a stack?
People standing in a queue at a ticket counter
Cars parked in a single-lane driveway
Customers waiting on hold for customer service
Books arranged alphabetically on a shelf