In a stack, how is the element that was added before the last added element accessed?
By searching the entire stack sequentially.
Directly using its index.
It's not possible to access elements directly in a stack.
By popping the top element first.
What is the primary advantage of using a linked list to implement a stack over an array?
Dynamic resizing capability
Faster push and pop operations
Lower memory usage
Simpler implementation
What is the time complexity of pushing an element onto a stack implemented using a linked list, assuming the push operation is implemented efficiently?
O(n)
O(n log n)
O(log n)
O(1)
Which of the following is a significant drawback of implementing a stack using a static array?
Slow push and pop operations
Fixed size limitation
High memory usage
Complex implementation
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
Which data structure, often used with stacks, helps manage function calls and their execution flow?
None of the above
Queue
Heap
Hash Table
What value does the 'peek' operation return if the stack is empty?
-1
0
null
It depends on the implementation.
In which scenario would you prefer using a stack over a queue data structure?
Storing a collection of songs to be played in a shuffled order.
Implementing an undo/redo functionality in a text editor.
Managing a print queue where tasks are processed in the order they arrive.
Simulating a first-in, first-out (FIFO) system.
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
Which data structure is most closely related to the concept of recursion?
Tree
Linked List
Stack