Infix to Postfix Questions
Thirty-five practice problems with answers, graded from basic precedence up to exam level — plus the reverse direction and the LeetCode problems that use the same algorithm.
Work each one out on paper first — write the stack and the output after every token — then open the answer. Every answer here was generated by the site's own converter, so the postfix, prefix and numeric values are all machine-checked.
Set 1 — basic precedence
Start here. No brackets, no associativity traps — just which operator binds tighter.
-
Q1Convert
A + Bto postfixShow the worked answer
Postfix:
A B +Prefix:
+ A BKey step: End of input — pop the remaining operator + to the output. · 4 steps. Open in the converter →
-
Q2Convert
A + B * Cto postfixShow the worked answer
Postfix:
A B C * +Prefix:
+ A * B CKey step: End of input — pop the remaining operators *, + to the output. · 6 steps. Open in the converter →
-
Q3Convert
A * B + Cto postfixShow the worked answer
Postfix:
A B * C +Prefix:
+ * A B CKey step: Pop * to the output (precedence at least "+"), then push "+". · 6 steps. Open in the converter →
-
Q4Convert
(A + B) * Cto postfixShow the worked answer
Postfix:
A B + C *Prefix:
* + A B CKey step: Pop + to the output, then discard the matching "(". · 8 steps. Open in the converter →
-
Q5Convert
A + B - Cto postfixShow the worked answer
Postfix:
A B + C -Prefix:
- + A B CKey step: Pop + to the output (precedence at least "-"), then push "-". · 6 steps. Open in the converter →
-
Q6Convert
A * B / Cto postfixShow the worked answer
Postfix:
A B * C /Prefix:
/ * A B CKey step: Pop * to the output (precedence at least "/"), then push "/". · 6 steps. Open in the converter →
Set 2 — associativity
Every expression here has two operators of equal precedence. This is the set most people get wrong.
-
Q7Convert
A - B - Cto postfixShow the worked answer
Postfix:
A B - C -Prefix:
- - A B CKey step: Pop - to the output (precedence at least "-"), then push "-". · 6 steps. Open in the converter →
-
Q8Convert
A / B / Cto postfixShow the worked answer
Postfix:
A B / C /Prefix:
/ / A B CKey step: Pop / to the output (precedence at least "/"), then push "/". · 6 steps. Open in the converter →
-
Q9Convert
A - B + Cto postfixShow the worked answer
Postfix:
A B - C +Prefix:
+ - A B CKey step: Pop - to the output (precedence at least "+"), then push "+". · 6 steps. Open in the converter →
-
Q10Convert
a ^ b ^ cto postfixShow the worked answer
Postfix:
a b c ^ ^Prefix:
^ a ^ b cKey step: End of input — pop the remaining operators ^, ^ to the output. · 6 steps. Open in the converter →
-
Q11Convert
A ^ B ^ C ^ Dto postfixShow the worked answer
Postfix:
A B C D ^ ^ ^Prefix:
^ A ^ B ^ C DKey step: End of input — pop the remaining operators ^, ^, ^ to the output. · 8 steps. Open in the converter →
-
Q12Convert
A * B % Cto postfixShow the worked answer
Postfix:
A B * C %Prefix:
% * A B CKey step: Pop * to the output (precedence at least "%"), then push "%". · 6 steps. Open in the converter →
Set 3 — brackets
Nested and side-by-side groups. Remember that brackets never appear in the output.
-
Q13Convert
(A + B) * (C - D)to postfixShow the worked answer
Postfix:
A B + C D - *Prefix:
* + A B - C DKey step: Pop - to the output, then discard the matching "(". · 12 steps. Open in the converter →
-
Q14Convert
A * (B + C) / Dto postfixShow the worked answer
Postfix:
A B C + * D /Prefix:
/ * A + B C DKey step: Pop * to the output (precedence at least "/"), then push "/". · 10 steps. Open in the converter →
-
Q15Convert
((A + B) * C) - Dto postfixShow the worked answer
Postfix:
A B + C * D -Prefix:
- * + A B C DKey step: Pop * to the output, then discard the matching "(". · 12 steps. Open in the converter →
-
Q16Convert
A + (B * C - D) / Eto postfixShow the worked answer
Postfix:
A B C * D - E / +Prefix:
+ A / - * B C D EKey step: Pop - to the output, then discard the matching "(". · 12 steps. Open in the converter →
-
Q17Convert
(A - B) ^ (C + D)to postfixShow the worked answer
Postfix:
A B - C D + ^Prefix:
^ - A B + C DKey step: Pop + to the output, then discard the matching "(". · 12 steps. Open in the converter →
Set 4 — exam level
Long expressions combining precedence, associativity and nesting. These are the shapes that turn up in past papers.
-
Q18Convert
A + B * C - D / Eto postfixShow the worked answer
Postfix:
A B C * + D E / -Prefix:
- + A * B C / D EKey step: Pop *, + to the output (precedence at least "-"), then push "-". · 10 steps. Open in the converter →
-
Q19Convert
A + B * C - (D / E ^ F) * Gto postfixShow the worked answer
Postfix:
A B C * + D E F ^ / G * -Prefix:
- + A * B C * / D ^ E F GKey step: Pop ^, / to the output, then discard the matching "(". · 16 steps. Open in the converter →
-
Q20Convert
K + L - M * N + (O ^ P) * W / U / V * T + Qto postfixShow the worked answer
Postfix:
K L + M N * - O P ^ W * U / V / T * + Q +Prefix:
+ + - + K L * M N * / / * ^ O P W U V T QKey step: Pop *, + to the output (precedence at least "+"), then push "+". · 24 steps. Open in the converter →
-
Q21Convert
a + b * c / d - e ^ f ^ gto postfixShow the worked answer
Postfix:
a b c * d / + e f g ^ ^ -Prefix:
- + a / * b c d ^ e ^ f gKey step: Pop /, + to the output (precedence at least "-"), then push "-". · 14 steps. Open in the converter →
-
Q22Convert
(a + b) * c - (d - e) ^ (f + g)to postfixShow the worked answer
Postfix:
a b + c * d e - f g + ^ -Prefix:
- * + a b c ^ - d e + f gKey step: Pop + to the output, then discard the matching "(". · 20 steps. Open in the converter →
Set 5 — numeric, with values
Convert to postfix and evaluate. Two marks instead of one, and the value is a free check on your conversion.
-
Q23Convert
3 + 4 * 2to postfixShow the worked answer
Postfix:
3 4 2 * +Prefix:
+ 3 * 4 2Value:
11Key step: End of input — pop the remaining operators *, + to the output. · 6 steps. Open in the converter →
-
Q24Convert
(3 + 4) * 2to postfixShow the worked answer
Postfix:
3 4 + 2 *Prefix:
* + 3 4 2Value:
14Key step: Pop + to the output, then discard the matching "(". · 8 steps. Open in the converter →
-
Q25Convert
2 ^ 3 ^ 2to postfixShow the worked answer
Postfix:
2 3 2 ^ ^Prefix:
^ 2 ^ 3 2Value:
512Key step: End of input — pop the remaining operators ^, ^ to the output. · 6 steps. Open in the converter →
-
Q26Convert
100 / 5 / 2to postfixShow the worked answer
Postfix:
100 5 / 2 /Prefix:
/ / 100 5 2Value:
10Key step: Pop / to the output (precedence at least "/"), then push "/". · 6 steps. Open in the converter →
-
Q27Convert
3 + 4 * 2 / (1 - 5) ^ 2to postfixShow the worked answer
Postfix:
3 4 2 * 1 5 - 2 ^ / +Prefix:
+ 3 / * 4 2 ^ - 1 5 2Value:
3.5Key step: Pop - to the output, then discard the matching "(". · 14 steps. Open in the converter →
-
Q28Convert
10 % 3 + 2 * 5to postfixShow the worked answer
Postfix:
10 3 % 2 5 * +Prefix:
+ % 10 3 * 2 5Value:
11Key step: Pop % to the output (precedence at least "+"), then push "+". · 8 steps. Open in the converter →
Set 6 — postfix to infix questions
The reverse direction. Give both the minimally bracketed infix and the fully bracketed form.
-
Q29Convert
A B + C *back to infixShow the worked answer
-
Q30Convert
A B C * +back to infixShow the worked answer
-
Q31Convert
A B C - -back to infixShow the worked answer
-
Q32Convert
a b c ^ ^back to infixShow the worked answer
-
Q33Convert
A B ^ C ^back to infixShow the worked answer
-
Q34Convert
a b + c d - *back to infixShow the worked answer
Infix:
(a + b) * (c - d)Fully bracketed:
((a + b) * (c - d))Prefix:
* + a b - c d -
Q35Convert
A B C * + D E / -back to infixShow the worked answer
Infix:
A + B * C - D / EFully bracketed:
((A + (B * C)) - (D / E))Prefix:
- + A * B C / D E
Mark-losing mistakes
| Mistake | Shows up as | Fix |
|---|---|---|
| Pushing on equal precedence | A - B - C → A B C - - | Pop on equal precedence for every left-associative operator |
Treating ^ as left associative | a ^ b ^ c → a b ^ c ^ | ^ is the one operator that does not pop its equals |
| Writing brackets into the output | ( A B + ) C * | Brackets are markers only; they are discarded |
| Forgetting the final flush | Output ends mid-expression | Pop everything left on the stack when the input ends |
| Showing only the answer | Full marks lost on a correct answer | Write the stack and output columns for every token |
There is a longer version of this list, with the reasoning behind each one, on the stack walkthrough.
LeetCode problems on this topic
Interview practice tends to test evaluation rather than conversion, but the shunting-yard algorithm is a clean solution to several of them.
| Problem | What it asks | Connection |
|---|---|---|
| Evaluate Reverse Polish Notation | Evaluate a postfix token list | Exactly the value-stack algorithm |
| Basic Calculator II | Evaluate infix with + - * / | Shunting-yard, or a running stack of terms |
| Basic Calculator | Infix with brackets and unary minus | Bracket handling, plus the unary case |
| Basic Calculator III | Brackets and all four operators | Full shunting-yard with an evaluation pass |
| Build Binary Expression Tree From Infix Expression | Produce the expression tree | Same algorithm, building nodes instead of emitting tokens |
If you can convert to postfix and evaluate it with a stack, all five reduce to bookkeeping. The C and Python, Java and C++ implementations are close to what you would submit.
Frequently asked questions
How do I practise infix to postfix conversion?
Work each expression by hand first, writing the stack and the output after every token, then reveal the answer and compare. Comparing only the final line hides where you went wrong; comparing the trace shows you the exact token where your stack diverged.
What kind of infix to postfix questions come up in exams?
Almost always one of four shapes: a plain precedence question, a bracketed expression, a chain of same-precedence operators to test associativity, and one with the exponent operator to test right associativity. The sets on this page follow that order.
Which infix to postfix question is most often got wrong?
Anything of the form A - B - C or A / B / C. Most people push on equal precedence instead of popping, which gives A B C - - and means A - (B - C). Exponentiation chains like a ^ b ^ c are the second most common, because that one really does push.
Are there LeetCode problems on this topic?
Yes, though they are usually framed as evaluation rather than conversion. Evaluate Reverse Polish Notation is the direct one. Basic Calculator and Basic Calculator II are infix evaluation problems where the shunting-yard algorithm is a clean solution, and Basic Calculator III adds brackets on top.
How do I check my own answer?
Convert your postfix answer back to infix. If it does not match the expression you started from, your answer is wrong — and the position where the two differ tells you which operator you misplaced. The postfix to infix converter on this site does the check in one paste.
Do I need to show the stack in the exam?
Usually yes. Most mark schemes award most of the marks for the working, not the final expression, so a correct answer with no trace can score poorly while a trace with one slip still scores well.