What real-world scenario accurately reflects the functioning of a stack?
People standing in a queue at a ticket counter
Customers waiting on hold for customer service
Cars parked in a single-lane driveway
Books arranged alphabetically on a shelf
What is the primary advantage of using a linked list to implement a stack over an array?
Lower memory usage
Dynamic resizing capability
Faster push and pop operations
Simpler implementation
What is the primary disadvantage of using stacks compared to other data structures?
Limited access to elements (only top)
Inability to store duplicate elements
Slow insertion and deletion at the end
High memory consumption
Which data structure is most closely related to the concept of recursion?
Tree
Linked List
Stack
Queue
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 both to the right and has a larger value.
The element that is lexicographically greater.
What happens when you try to 'pop' an element from an empty stack?
A special value (like -1) is returned.
A random element from the stack is removed.
The program crashes.
It depends on the specific implementation of the stack.
Which data structure, often used with stacks, helps manage function calls and their execution flow?
Heap
Hash Table
None of the above
If you implement a stack using an array, what problem might you encounter if you keep pushing elements onto the stack without any limit?
Memory Leak
Segmentation Fault
Stack Overflow
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(1)
O(n)
O(n log n)
O(log n)
In a stack, how is the element that was added before the last added element accessed?
By popping the top element first.
It's not possible to access elements directly in a stack.
By searching the entire stack sequentially.
Directly using its index.