MCQ Infix Postfix Prefix

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Infix to Postfix/Prefix Expressions - MCQs:

1. Which of the following is true about infix, postfix, and prefix expressions?
a) Infix expressions require parentheses for precedence, while postfix and prefix
expressions do not.
b) Postfix expressions require parentheses for operator precedence.
c) Prefix expressions cannot be evaluated without parentheses.
d) Infix and postfix expressions are evaluated from right to left.
Answer: a) Infix expressions require parentheses for precedence, while postfix and prefix
expressions do not.

2. Which data structure is most suitable for converting an infix expression to a postfix
expression?
a) Queue
b) Stack
c) Array
d) Tree
Answer: b) Stack

3. Which of the following infix expressions corresponds to the postfix expression AB+C*?
a) (A + B) * C
b) A * (B + C)
c) A + B * C
d) (A * B) + C
Answer: a) (A + B) * C

4. What is the postfix form of the 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 * +

5. What is the prefix form of the infix expression (A + B) * (C - D)?


a) * + A B - C D
b) + * A B C D -
c) A B + C D - *
d) A + B * C - D
Answer: a) * + A B - C D

6. Which of the following is the correct postfix conversion of the infix expression A * (B + C)
/ D?
a) A B C + * D /
b) A * B + C / D
c) A B * C D + /
d) A B + C * D /
Answer: a) A B C + * D /

7. How is operator precedence handled in postfix expressions?


a) Operator precedence is handled using parentheses.
b) Operator precedence is determined by the order of appearance in postfix notation.
c) Operator precedence is not applicable in postfix notation.
d) Operator precedence is based on the operators' positions relative to the operands.
Answer: b) Operator precedence is determined by the order of appearance in postfix
notation.

8. Which of the following steps is NOT part of the process to convert an infix expression to
postfix?
a) Operands are added directly to the output.
b) Operators are pushed onto a stack based on precedence.
c) Parentheses are ignored.
d) Higher precedence operators are popped from the stack before lower precedence
ones.
Answer: c) Parentheses are ignored.

9. What is the postfix form of the infix expression A + (B * C - D) / E?


a) A B C * D - + E /
b) A B C D * - E / +
c) A B * C D - + E /
d) A B C * D / E - +
Answer: a) A B C * D - + E /

10. Which of the following is true about postfix and prefix expressions?
a) Postfix and prefix expressions always need parentheses for evaluation.
b) In postfix expressions, operators appear before their operands.
c) In prefix expressions, operators appear before their operands.
d) Postfix expressions are easier to evaluate than prefix expressions.
Answer: c) In prefix expressions, operators appear before their operands.

11. What is the time complexity of converting an infix expression to a postfix expression
using a stack?
a) O(n^2)
b) O(log n)
c) O(n)
d) O(n log n)
Answer: c) O(n)

12. Which of the following is the correct postfix form of the expression A * B + C / D?
a) A B * C D / +
b) A B C * + D /
c) A B * C / D +
d) A B * + C / D
Answer: a) A B * C D / +

13. Which of the following is the prefix form of the infix expression A * B + C / D?
a) * + A B / C D
b) + * A B / C D
c) * A B / + C D
d) / + * A B C D
Answer: b) + * A B / C D

14. Which of the following postfix expressions is equivalent to the infix expression (A + B) *
(C + D)?
a) A B C D + * +
b) A B + C D + *
c) A + B * C + D
d) A B + * C D +
Answer: b) A B + C D + *

15. What is the prefix form of the infix expression (A - B) + (C / D)?


a) - A B / C D +
b) + - A B / C D
c) * - A B / C D
d) - + A B / C D
Answer: b) + - A B / C D

16. Which of the following is true when evaluating a postfix expression?


a) Operators are pushed onto the stack.
b) Operands are pushed onto the stack, and operators pop them for evaluation.
c) Operators and operands are pushed onto the stack together.
d) Only parentheses are used for evaluation.
Answer: b) Operands are pushed onto the stack, and operators pop them for evaluation.

17. What is the postfix form of the infix expression A + B * C - D?


a) A B C * + D -
b) A + B C * - D
c) A + B * C - D
d) A B C + * D -
Answer: a) A B C * + D -

18. Which of the following describes an advantage of using postfix expressions for
evaluation?
a) Parentheses are required to maintain operator precedence.
b) It is more readable than infix expressions.
c) Postfix expressions eliminate the need for operator precedence rules.
d) Postfix expressions are evaluated from right to left.
Answer: c) Postfix expressions eliminate the need for operator precedence rules.

19. What is the prefix form of the infix expression A / B - C + D * E?


a) + - / A B C * D E
b) - / A B + * D E C
c) + - / A B C * D E
d) + * D E / A B - C
Answer: c) + - / A B C * D E

20. Which of the following is true about the evaluation of prefix expressions?
a) It is evaluated from right to left using a stack.
b) It is evaluated from left to right using a stack.
c) No stack is required to evaluate prefix expressions.
d) It is evaluated using recursion instead of a stack.
Answer: a) It is evaluated from right to left using a stack.

You might also like