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?
BeginnerShow 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?
BeginnerShow 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 '('?
BeginnerShow 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.
BeginnerShow 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?
BeginnerShow 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?
BeginnerShow 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?
BeginnerShow 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?
BeginnerShow 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?
BeginnerShow 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?
BeginnerShow 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?
BeginnerShow 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?
BeginnerShow 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?
BeginnerShow 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?
BeginnerShow 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?
IntermediateShow 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?
IntermediateShow 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?
IntermediateShow 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?
IntermediateShow 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?
IntermediateShow 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?
IntermediateShow 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?
IntermediateShow 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?
IntermediateShow 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 *?
IntermediateShow 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.
IntermediateShow 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?
AdvancedShow 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?
AdvancedShow 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)?
AdvancedShow 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?
AdvancedShow 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)?
AdvancedShow answer & explanation
- - A B C
Left associativity means (A - B) - C, so the prefix is - - A B C.
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