Which of the following stack operations has a time complexity of O(1) in both array-based and linked list-based implementations?
Pop
All of the above
Peek
Push
In the context of expression parsing, what role does a stack play?
Storing the lexical tokens identified in the expression.
Optimizing the expression for better performance.
Evaluating the parsed expression directly.
Generating machine code from the expression.
What is the result of evaluating the prefix expression '-+5*234'?
-7
-17
7
17
What is a potential drawback of using a linked list-based stack compared to an array-based stack?
Higher memory usage due to the overhead of storing pointers
Increased time complexity for push and pop operations
Limited stack size
Inability to handle dynamic resizing
What is the primary difference between 'pop' and 'peek' operations on a stack?
'Pop' retrieves the top element's value, while 'peek' removes it from the stack.
'Pop' is used for stacks, while 'peek' is used for queues.
'Pop' and 'peek' are interchangeable terms for the same operation.
'Pop' removes the top element, while 'peek' only retrieves its value without removing it.
What is the purpose of the 'top' pointer in an array-based stack implementation?
To store the value of the top element in the stack
To store the maximum size of the stack
To point to the bottom element of the stack
To track the index of the next available position for insertion
How are stacks utilized in syntax parsing within compilers?
For performing code optimization.
To check for matching parentheses, braces, and brackets.
For storing the symbol table of variables.
To generate intermediate code during compilation.
What is the primary role of a stack in expression evaluation?
Performing arithmetic calculations on operands.
Evaluating the precedence of operators.
Converting infix expressions to postfix.
Storing the variables used in the expression.
What is the primary disadvantage of implementing a stack using a fixed-size array?
Complex implementation requiring advanced pointer manipulation
Inability to handle stacks larger than the predetermined size
Higher memory usage compared to dynamic arrays
Which real-life scenario most accurately reflects the LIFO (Last In First Out) principle of a stack data structure?
A queue of people waiting for a bus.
A list of tasks sorted by priority.
A tree of files and folders on a computer.
A stack of plates on a table.