Applications of stacks (expression evaluation, recursion) MCQs

By: Prof. Dr. Fazal Rehman Shamil | Last updated: September 20, 2024

In which of the following applications is a stack commonly used?

a) Sorting
b) Searching
c) Expression evaluation
d) Hashing
Answer: c) Expression evaluation
Which data structure is often used for implementing the undo feature in text editors?

a) Queue
b) Stack
c) Linked list
d) Tree
Answer: b) Stack
What is the primary advantage of using a stack in expression evaluation?

a) Allows random access to elements
b) Simplifies complex arithmetic operations
c) Facilitates tracing program execution
d) Handles function calls efficiently
Answer: c) Facilitates tracing program execution
Which of the following is NOT a valid application of a stack?

a) Function call management
b) Backtracking in algorithms
c) Arithmetic expression parsing
d) Binary search tree traversal
Answer: d) Binary search tree traversal
What is the role of a stack in evaluating postfix expressions?

a) Stores operands
b) Stores operators
c) Stores both operands and operators
d) Manages parentheses
Answer: a) Stores operands
*Which of the following expressions is equivalent to the postfix expression “3 4 + 5 “?

a) (3 + 4) * 5
b) 3 + (4 * 5)
c) 3 + 4 * 5
d) (3 * 4) + 5
Answer: a) (3 + 4) * 5
In expression evaluation using a stack, what is done when encountering an operand?

a) Push it onto the stack
b) Pop it from the stack
c) Ignore it
d) Perform arithmetic operations
Answer: a) Push it onto the stack
What is the primary purpose of using a stack in recursion?

a) To store local variables
b) To manage function calls and return addresses
c) To optimize memory usage
d) To prevent stack overflow errors
Answer: b) To manage function calls and return addresses
Which of the following describes the behavior of a stack during recursion?

a) Each recursive call creates a new stack frame
b) Each recursive call shares the same stack frame
c) Recursion does not use a stack
d) Stack frames are created only for base cases
Answer: a) Each recursive call creates a new stack frame
What is tail recursion?

a) A recursion where recursive call is not the last operation
b) A recursion where recursive call is the last operation
c) A recursion that doesn’t involve function calls
d) A recursion that involves nested functions
Answer: b) A recursion where recursive call is the last operation
Which of the following statements about postfix expressions is true?

a) They are easier to read than infix expressions
b) They are evaluated from left to right
c) They require parentheses to specify order of operations
d) They are converted to infix using stacks
Answer: d) They are converted to infix using stacks
What is the time complexity of evaluating an arithmetic expression using a stack-based approach?

a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: b) O(n)
Which of the following operations is NOT typically performed using a stack in algorithm design?

a) Depth-first search traversal
b) Topological sorting
c) Breadth-first search traversal
d) Shortest path calculation
Answer: c) Breadth-first search traversal
In an infix expression, how are parentheses handled during evaluation using a stack?

a) They are ignored
b) They are evaluated first
c) They are removed from the expression
d) They determine the order of operations
Answer: b) They are evaluated first
Which data structure is typically used to implement a stack in programming languages?

a) Array
b) Linked list
c) Tree
d) Graph
Answer: a) Array
What is the main advantage of using postfix notation in expressions?

a) It eliminates the need for parentheses
b) It allows for easier debugging
c) It reduces the number of operands
d) It speeds up evaluation time
Answer: a) It eliminates the need for parentheses
Which of the following is a valid postfix notation for the infix expression “a + b * c”?

a) a b + c *
b) a b c * +
c) a b c + *
d) a * b + c
Answer: b) a b c * +
What is the key advantage of using postfix notation for arithmetic expressions?

a) Easier conversion to prefix notation
b) Better handling of operator precedence
c) Reduced memory usage
d) Faster execution time
Answer: d) Faster execution time
In recursion, what is the base case?

a) The case where the recursion is infinite
b) The starting point of recursion
c) The case that terminates the recursion
d) The last step of recursion
Answer: c) The case that terminates the recursion
Which of the following is NOT a limitation of using recursion?

a) Limited stack size
b) Difficulty in understanding and debugging
c) Slower execution compared to iterative methods
d) Difficulty in handling complex algorithms
Answer: c) Slower execution compared to iterative methods

 

Data Structures MCQs

Basic Concepts

  1. Introduction to Data Structures
  2. Complexity Analysis MCQs

Linear Data Structures MCQs

  1. Arrays MCQs
  2. Linked Lists MCQs
  3. Stacks MCQs
  4. Queues MCQs

Non-Linear Data Structures MCQs

  1. Trees MCQs
  2. Heaps MCQs
  3. Graphs MCQs

Hashing MCQs MCQs

  1. Hash Tables

Sorting and Searching Algorithms MCQs 

  1. Sorting Algorithms MCQs
  2. Searching Algorithms MCQs

Miscellaneous

  1. Memory Management in data structures MCQs
  2. String Manipulation Algorithms MCQs
  1. Data Structures MCQs 1
  2. Data Structures MCQs 2
  3. Data Structures MCQs 3
  4. Data Structures MCQs 4
  5. Data Structures MCQs 5
  6. Stacks Solved MCQs
  7. Queues MCQs
  8. pointer mcqs
  9. Array MCQs