Infix, Prefix and Postfix Notation: Conversion and Evaluation (ISC Class 12 Computer Science)
Updated 17 October 2026 · Draft, not yet fact-checked
In infix the operator is between operands (A + B), in prefix before them (+ A B) and in postfix after them (A B +). Prefix and postfix need no brackets or precedence rules. Convert by fully bracketing the infix expression by precedence and associativity, then moving each operator before (prefix) or after (postfix) its two operands; evaluate postfix with a stack scanning left to right.
Understand Infix, Prefix and Postfix Notation: Conversion and Evaluation
Three notations.
- Infix:
A + B. Needs precedence and brackets. - Prefix (Polish):
+ A B. Operator first. - Postfix (reverse Polish):
A B +. Operator last.
In prefix and postfix the order of operators already fixes the order of evaluation, so brackets are never needed.
Precedence and associativity. Highest to lowest: ^ (right to left), then * / (left to right), then + - (left to right). Brackets override. So A - B - C is (A - B) - C, and A ^ B ^ C is A ^ (B ^ C).
Hand method (fully bracket). (1) Bracket every operation using precedence and associativity so each bracket has exactly two operands. (2) For postfix, move each operator to just after its right bracket; for prefix, move each operator to just before its left bracket. (3) Remove the brackets. Example: A + B * C becomes A + (B * C); postfix A B C * +; prefix + A * B C.
Infix to postfix with a stack. Scan left to right. Operand: output at once. (: push. ): pop and output until (, which is discarded. Operator: pop and output operators of higher or equal precedence (for left-associative operators; only higher for ^) from the top of the stack, then push it. At the end pop everything to the output.
Infix to prefix. Reverse the expression (swapping brackets), convert as above but with the rule for equal precedence changed (pop only higher precedence), then reverse the result. The hand method is quicker for small examples; use either and show the steps.
Evaluating postfix. Scan left to right: push operands; for an operator pop two values (first popped is the right operand b, second is the left operand a), compute a op b, push the result. The final stack top is the value. Prefix is evaluated by scanning right to left, where the first value popped is the left operand.
Stack and queue classes are in the previous topic.
Infix, Prefix and Postfix Notation: Conversion and Evaluation: key facts
- Notation forms
Infix A + B Prefix + A B Postfix A B + Prefix and postfix need no brackets - Operator before, between and after the operands.
- Precedence and associativity
Highest: ^ right to left Then multiply and divide left to right Then add and subtract left to right Brackets first - A - B - C means (A - B) - C.
- Postfix evaluation
- Scan left to right
- Operand: push
- Operator: pop b, pop a, push (a op b)
- Answer is the last value on the stack
- The first popped value is the right operand.
- Stack conversion rules
- Operand: output
- (: push
- ): pop to output until (
- Operator: pop equal or higher precedence, then push
- Empty the stack at the end.
How to answer Infix, Prefix and Postfix Notation: Conversion and Evaluation questions
Use this routine to convert or evaluate.
- 1Write the infix expression and bracket every operation in the correct order (by precedence, then left to right).
- 2For postfix, write each operator after its two operands; for prefix, before them. Work from the innermost bracket out.
- 3Remove all brackets and check the number of operators is one less than the number of operands.
- 4If a stack trace is asked, make a table with columns symbol, stack and output.
- 5To evaluate, make a stack table and apply each operator to the top two values.
- 6Check by evaluating the infix form with the same values, if given.
Infix, Prefix and Postfix Notation: Conversion and Evaluation in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Calculator without brackets
Suppose a postfix calculator evaluates 8 2 / 3 + 4 * by pushing numbers and applying operators to the top two numbers.
What does it display?
Try it first, then show the solutionSolution
- 8 2 / gives 4; 4 3 + gives 7; 7 4 * gives 28.
- No brackets or precedence were needed.
Answer: 28
Memory hook: Numbers wait on the stack until an operator picks the top two.
Billing formula as a recipe
Suppose a billing formula is written as (P + Q) * R and the system stores it in postfix.
What is its postfix form?
Try it first, then show the solutionSolution
- P + Q becomes P Q +.
- Then multiply by R: P Q + R *.
Answer: P Q + R *
Memory hook: Finish the brackets first, operator last.
Tricks to remember Infix, Prefix and Postfix Notation: Conversion and Evaluation
Short memory aids. Say each one aloud once, then use it on a question the same day.
Pre, in, post = operator position
Pre = before, in = between, post = after.
Use it when: Naming the notation.
Bracket, then move
Fully bracket first; moving operators is then mechanical.
Use it when: Hand conversion.
Equal pops for left-to-right
Equal precedence on the stack leaves first, except for ^.
Use it when: Stack conversion.
Second popped is the left
In postfix evaluation: pop b first, then a, compute a op b.
Use it when: Subtraction and division order.
Infix, Prefix and Postfix Notation: Conversion and Evaluation: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Simple postfix · 1 mark · MCQBoard level
The postfix form of A + B is
(a) + A B (b) A B + (c) A + B (d) B A +
Try it first, then show the solutionSolution
- In postfix the operator follows its operands.
Answer: (b) A B +
Example 2: Hand conversion · 4 marks · Short answerHarder board level
Convert (P + Q) * R - S / (T - U) to (a) postfix and (b) prefix.
Try it first, then show the solutionSolution
- Bracket: (((P + Q) * R) - (S / (T - U))). (1 mark)
- Postfix: P Q + gives P Q + R *; S T U - /; join with the minus: P Q + R * S T U - / -. (1.5 marks)
- Prefix: + P Q gives * + P Q R; - T U gives / S - T U; join: - * + P Q R / S - T U. (1.5 marks)
Answer: Postfix: P Q + R * S T U - / -. Prefix: - * + P Q R / S - T U
Example 3: Stack conversion to postfix · 4 marks · Short answerHarder board level
Convert A * (B + C) / D to postfix, showing the stack and the output after each symbol.
Try it first, then show the solutionSolution
- A: output A. *: push (stack *). (: push (stack * (). B: output AB. +: push (stack * ( +). C: output ABC. (1.5 marks)
- On ) pop + to the output and remove the bracket: output ABC+, stack *. (1 mark)
- On / the * has equal precedence, so pop it: output ABC+*, then push /. D: output ABC+*D. At the end pop /. (1 mark)
- Result: A B C + * D /. (0.5 mark)
Answer: A B C + * D /
Example 4: Postfix evaluation · 3 marks · Short answerHarder board level
Evaluate the postfix expression 8 2 / 3 + 4 * showing the stack after each symbol.
Try it first, then show the solutionSolution
- Push 8, push 2: stack 8, 2. For /: b = 2, a = 8, result 4: stack 4. (1 mark)
- Push 3: stack 4, 3. For +: 7: stack 7. (1 mark)
- Push 4: stack 7, 4. For *: 28. The answer is 28. (1 mark)
Answer: 28
Example 5: Case: formula received in postfix · 4 marks · Case-basedHOTS / competency
Suppose a system sends a formula as A B + C D - * and the values are A = 2, B = 3, C = 9, D = 4.
(i) Write the infix form. (1 mark)
(ii) Evaluate it with the stack. (2 marks)
(iii) Write the prefix form. (1 mark)
Try it first, then show the solutionSolution
- (i) A B + gives (A + B); C D - gives (C - D); the final * joins them: (A + B) * (C - D).
- (ii) A + B = 2 + 3 = 5; C - D = 9 - 4 = 5; 5 * 5 = 25. On the stack: 2, 3 then + gives 5; 9, 4 then - gives 5; then * gives 25.
- (iii) * + A B - C D.
Answer: (i) (A + B) * (C - D) (ii) 25 (iii) * + A B - C D
Where students lose marks in Infix, Prefix and Postfix Notation: Conversion and Evaluation
The slips examiners see most often, and what to write instead.
Mistake: Ignoring left-to-right associativity
A - B - C is (A - B) - C, so the first minus is done first.
Wrong working
A - B - C to postfix gives A B C - -
Right working
A - B - C to postfix gives A B - C -
Do this: Bracket from the left for equal precedence.
Usually costs: 1 mark
Mistake: Swapped operands in evaluation
The first popped value is the right operand.
Wrong working
8 2 / gives 2 / 8 = 0.25
Right working
8 2 / gives 8 / 2 = 4
Do this: Pop b, pop a, compute a op b.
Usually costs: 1 mark
Mistake: Leaving brackets in the answer
Prefix and postfix forms never contain brackets.
Wrong working
A B + (C)
Right working
A B + C
Do this: Remove brackets after moving operators.
Usually costs: 1 mark
Exam tips
- Fully bracket the infix expression before moving any operator.
- Show the stack and output columns in a stack conversion table.
- Count operators and operands as a check (operands = operators + 1).
- Pop b before a when evaluating postfix.
- Mention that ^ is right-associative when it appears.
Practice questions on Infix, Prefix and Postfix Notation: Conversion and Evaluation
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
The postfix form of (A + B) * C is
(a) A B + C * (b) A B C + * (c) * + A B C (d) A + B * CHint
Do the bracket first.
Answer
(a) A B + C *
Q2 · 2 marks · Short answerBoard level
Why are brackets not needed in prefix and postfix notation?
Hint
Think of operator position.
Answer
The position of each operator relative to its operands already shows the order of evaluation, so there is no ambiguity and no precedence rules or brackets are needed.
Q3 · 3 marks · Short answerHarder board level
Convert A + B * C ^ D to postfix and to prefix, stating the associativity rule used for ^.
Hint
^ is right-associative and highest.
Answer
Bracket: A + (B * (C ^ D)). Postfix: C ^ D gives C D ^, B * gives B C D ^ *, then A B C D ^ * +. Prefix: ^ C D, then * B ^ C D, then + A * B ^ C D. The operator ^ is evaluated before * and +.
Q4 · 3 marks · Short answerHarder board level
Evaluate the postfix expression 9 3 / 2 4 * + 1 - with a stack table.
Hint
Pop b first, then a.
Answer
9 3 / gives 3; 2 4 * gives 8; stack 3, 8; + gives 11; push 1, - gives 11 - 1 = 10. Answer: 10.
Q5 · 4 marks · Case-basedHOTS / competency
Evaluate the prefix expression - * 6 3 + 8 2 by scanning from the right, then write the infix form and check the value.
Hint
The first value popped is the left operand when scanning prefix right to left.
Answer
Scan right to left: push 2, push 8; + pops 8 and 2 giving 10; push 3, push 6; * pops 6 and 3 giving 18; - pops 18 and 10 giving 18 - 10 = 8. Infix: (6 * 3) - (8 + 2) = 18 - 10 = 8, matching.
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.What is the postfix of A * B + C?Show answer
A B * C +.
2.What is the prefix of A + B?Show answer
+ A B.
3.Which operator is right-associative?Show answer
^.
4.Which structure is used to evaluate postfix?Show answer
A stack.
5.Do prefix expressions contain brackets?Show answer
No.
6.What happens at a ) in infix to postfix conversion?Show answer
Operators are popped to the output until the matching ( is reached.
Infix, Prefix and Postfix Notation: Conversion and Evaluation: frequently asked questions
What is the difference between infix, prefix and postfix notation?
They differ in the position of the operator: between the operands (infix), before them (prefix) and after them (postfix).
How do you convert infix to postfix?
Bracket by precedence and associativity and move each operator after its operands, or use a stack: output operands, push operators after popping those of higher or equal precedence, and handle brackets.
How is a postfix expression evaluated?
Scan left to right, push operands, and at each operator pop two values, apply the operator and push the result; the last value is the answer.
Why is postfix used in computers?
It removes the need for brackets and precedence rules, so a stack can evaluate it directly in one left-to-right pass.