Stack Expression Conversion: 29 MCQs with answers

All 29 multiple-choice questions from this kit, free and with no sign-up.

Warm-up · 14 questions

Q1. In the context of expression conversion, what is the primary role of a stack?

Beginner
A To store the final converted expression B To evaluate the expression directly C To sort the operands D To temporarily hold operators and parentheses
Show answer & explanation

To temporarily hold operators and parentheses

The stack is used to temporarily store operators and parentheses so that their precedence and associativity can be handled correctly during conversion.

Q2. Which notation places the operator after its operands?

Beginner
A Postfix B Infix C Reverse Polish Notation D Prefix
Show answer & explanation

Postfix

Postfix notation (also called Reverse Polish Notation) places the operator after its operands, e.g., AB+.

Q3. When converting infix to postfix using a stack, what is done with an opening parenthesis '('?

Beginner
A It is immediately output to the postfix expression B It causes the stack to be popped until empty C It is pushed onto the stack D It is ignored
Show answer & explanation

It is pushed onto the stack

An opening parenthesis is pushed onto the stack to mark a subexpression boundary; it will later be popped when the matching closing parenthesis is encountered.

Q4. In infix to postfix conversion, operands are output directly without being pushed onto the stack.

Beginner
A True B False
Show answer & explanation

True

Operands are immediately appended to the output expression; only operators and parentheses are pushed onto the stack.

Q5. What does a stack hold during expression conversion?

Beginner
A Only operands B Operands and operators C Only operators D Operators and left parentheses
Show answer & explanation

Operators and left parentheses

The stack holds operators and left parentheses that are waiting to be processed.

Q6. What is the main reason for using a stack in infix to postfix conversion?

Beginner
A To evaluate expressions directly B To reorder operators based on precedence C To keep track of output D To store operands
Show answer & explanation

To reorder operators based on precedence

The stack is used to reorder operators based on their precedence and associativity.

Q7. In which notation does the operator appear after its operands?

Beginner
A Infix B Prefix C None of the above D Postfix
Show answer & explanation

Postfix

In postfix notation, the operator appears after its operands, which is also known as Reverse Polish Notation.

Q8. What happens when a closing parenthesis ')' is encountered in infix to postfix conversion?

Beginner
A Operators are popped to output until '(' is found B The process ends immediately C It is added to the output D Operators are pushed onto the stack
Show answer & explanation

Operators are popped to output until '(' is found

When a closing parenthesis is encountered, operators are popped from the stack to the output until the matching opening parenthesis is found.

Q9. What is the first step in the infix to postfix conversion algorithm?

Beginner
A Reverse the expression B Push all operands onto the stack C Scan from left to right D Pop all operators from the stack
Show answer & explanation

Scan from left to right

The first step in the infix to postfix conversion algorithm is to scan the expression from left to right.

Q10. What does the term 'associativity' refer to in expression conversion?

Beginner
A The direction in which operators are processed B The type of operators used C The grouping of operands D The order of operations
Show answer & explanation

The direction in which operators are processed

Associativity refers to the direction in which operators of the same precedence are processed, affecting how expressions are evaluated.

Q11. What is the result of converting the infix expression 'A + B * C' to postfix?

Beginner
A A B C * + B C B A + * C B C * A + D A + B * C
Show answer & explanation

A B C * +

The postfix conversion of 'A + B * C' results in 'A B C * +' as operators are placed after their operands.

Q12. What is the purpose of parentheses in infix expressions?

Beginner
A To indicate output order B To store operators C To change operator precedence D To represent operands
Show answer & explanation

To change operator precedence

Parentheses are used in infix expressions to indicate grouping and change the order of operator precedence.

Q13. What is the final step in the infix to postfix conversion process?

Beginner
A Reverse the output B Discard all operators C Pop all remaining operators from the stack D Push all operands to the output
Show answer & explanation

Pop all remaining operators from the stack

The final step in the infix to postfix conversion process is to pop all remaining operators from the stack to the output.

Q14. Which of the following expressions requires parentheses in infix notation?

Beginner
A A + B * C B A * B + C C A + B D A * (B + C)
Show answer & explanation

A + B * C

The expression 'A + B * C' requires parentheses to indicate the correct order of operations due to operator precedence.

Building up · 10 questions

Q15. In infix to postfix conversion, when a closing parenthesis ')' is encountered, what happens?

Intermediate
A It is pushed onto the stack B The stack is cleared C It is output directly D Operators are popped and output until an opening parenthesis is popped
Show answer & explanation

Operators are popped and output until an opening parenthesis is popped

A closing parenthesis triggers popping operators from the stack and appending them to the output until the matching opening parenthesis is popped (and discarded).

Q16. What is the time complexity of converting an infix expression to postfix using a stack?

Intermediate
A O(n^2) B O(n log n) C O(n) D O(1)
Show answer & explanation

O(n)

Each token is processed once, and each operator is pushed and popped at most once, leading to linear time complexity O(n).

Q17. Which of the following is the postfix equivalent of the infix expression A + B * C?

Intermediate
A A B C * + B * A B C + C A B C + * D A B + C *
Show answer & explanation

A B C * +

Multiplication has higher precedence than addition, so B*C is evaluated first, resulting in postfix: A B C * +.

Q18. What is the postfix form of the infix expression (A + B) * C?

Intermediate
A * A B C B A B + C * C A B + * C D A B C * +
Show answer & explanation

A B + C *

Parentheses force addition first, so A+B is computed, then multiplied by C, giving postfix: A B + C *.

Q19. When converting infix to prefix, the expression is usually scanned from which direction?

Intermediate
A Either direction B Left to right C Right to left D From the middle outward
Show answer & explanation

Right to left

For infix to prefix conversion, the expression is scanned from right to left to handle operator precedence correctly, and the result is reversed at the end.

Q20. Which of the following is the prefix equivalent of the infix expression A + B * C?

Intermediate
A + A * B C B A + * B C C + * A B C D * + A B C
Show answer & explanation

+ A * B C

Multiplication has higher precedence, so B*C is grouped first, then addition: + A * B C.

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

Intermediate
A + * A B C B * A + B C C + A B * C D * + A B C
Show answer & explanation

* + A B C

Parentheses force addition first, then multiplication: * + A B C.

Q22. When converting postfix to infix using a stack, what is done when an operand is encountered?

Intermediate
A It is ignored B It is used to pop two operands C It is pushed onto the stack D It is output directly
Show answer & explanation

It is pushed onto the stack

In postfix to infix conversion, operands are pushed onto the stack. When an operator is encountered, two operands are popped, combined, and the result is pushed back.

Q23. What is the infix equivalent of the postfix expression A B + C *?

Intermediate
A A + (B * C) B A + B * C C A * (B + C) D (A + B) * C
Show answer & explanation

(A + B) * C

The postfix expression is evaluated as A+B first, then multiplied by C, so the infix is (A + B) * C.

Q24. When converting infix to prefix, the expression is scanned from left to right, and the result is reversed at the end.

Intermediate
A True B False
Show answer & explanation

False

For infix to prefix conversion, the expression is scanned from right to left, and then the result is reversed to obtain the prefix expression.

Topper level · 5 questions

Q25. Which of the following is NOT a valid use of a stack in expression conversion?

Advanced
A Handling operator precedence B Handling associativity C Storing the final output expression D Handling parentheses
Show answer & explanation

Storing the final output expression

The stack is used for temporary storage of operators and parentheses; the final output is typically stored in a separate list or string, not on the stack.

Q26. In infix to postfix conversion, when an operator is read, what determines whether it is pushed onto the stack or an operator is popped first?

Advanced
A The length of the expression B The position of the operator in the expression C The operator's precedence and associativity compared to the top of the stack D The number of operands in the expression
Show answer & explanation

The operator's precedence and associativity compared to the top of the stack

The decision is based on precedence and associativity: if the incoming operator has lower or equal precedence (and is left-associative), the top operator is popped first.

Q27. Which of the following correctly represents the postfix expression for the infix expression A - B - C (left-associative)?

Advanced
A A B - C B A B C - - C A B - C - D A B C - -
Show answer & explanation

A B - C -

Subtraction is left-associative, so (A - B) - C is evaluated, giving postfix A B - C -.

Q28. What is the postfix expression for the infix expression A ^ B ^ C when the exponentiation operator is right-associative?

Advanced
A A B C ^ ^ B A B C ^ C A B ^ C ^ D A B ^ C
Show answer & explanation

A B C ^ ^

Right associativity means A ^ (B ^ C), so the postfix is A B C ^ ^.

Q29. Which of the following is the prefix expression for the infix expression A - B - C (left-associative)?

Advanced
A - A B - C B - - A B C C - A - B C D - - A B C
Show answer & explanation

- - A B C

Left associativity means (A - B) - C, so the prefix is - - A B C.

Make your own

Your notes can be a kit like these

Every kit here was made from real study material. Point Veda at a chapter, a PDF, a photo or a link and get notes, flashcards, practice MCQs, games and a scored test — free, in 42 languages.

  • Chapter notes
  • Flashcards
  • Practice MCQs
  • Scored tests
  • Exam prep

Get Veda free See what students get

Free to start · No ads · Works in 42 languages