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.

How to use this page

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.

0 correct 0 of 35 attempted

Set 1 — basic precedence

Start here. No brackets, no associativity traps — just which operator binds tighter.

  1. Q1Convert A + B to postfix

    Show the worked answer

    Postfix: A B +

    Prefix: + A B

    Key step: End of input — pop the remaining operator + to the output.  ·  4 steps. Open in the converter →

  2. Q2Convert A + B * C to postfix

    Show the worked answer

    Postfix: A B C * +

    Prefix: + A * B C

    Key step: End of input — pop the remaining operators *, + to the output.  ·  6 steps. Open in the converter →

  3. Q3Convert A * B + C to postfix

    Show the worked answer

    Postfix: A B * C +

    Prefix: + * A B C

    Key step: Pop * to the output (precedence at least "+"), then push "+".  ·  6 steps. Open in the converter →

  4. Q4Convert (A + B) * C to postfix

    Show the worked answer

    Postfix: A B + C *

    Prefix: * + A B C

    Key step: Pop + to the output, then discard the matching "(".  ·  8 steps. Open in the converter →

  5. Q5Convert A + B - C to postfix

    Show the worked answer

    Postfix: A B + C -

    Prefix: - + A B C

    Key step: Pop + to the output (precedence at least "-"), then push "-".  ·  6 steps. Open in the converter →

  6. Q6Convert A * B / C to postfix

    Show the worked answer

    Postfix: A B * C /

    Prefix: / * A B C

    Key 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.

  1. Q7Convert A - B - C to postfix

    Show the worked answer

    Postfix: A B - C -

    Prefix: - - A B C

    Key step: Pop - to the output (precedence at least "-"), then push "-".  ·  6 steps. Open in the converter →

  2. Q8Convert A / B / C to postfix

    Show the worked answer

    Postfix: A B / C /

    Prefix: / / A B C

    Key step: Pop / to the output (precedence at least "/"), then push "/".  ·  6 steps. Open in the converter →

  3. Q9Convert A - B + C to postfix

    Show the worked answer

    Postfix: A B - C +

    Prefix: + - A B C

    Key step: Pop - to the output (precedence at least "+"), then push "+".  ·  6 steps. Open in the converter →

  4. Q10Convert a ^ b ^ c to postfix

    Show the worked answer

    Postfix: a b c ^ ^

    Prefix: ^ a ^ b c

    Key step: End of input — pop the remaining operators ^, ^ to the output.  ·  6 steps. Open in the converter →

  5. Q11Convert A ^ B ^ C ^ D to postfix

    Show the worked answer

    Postfix: A B C D ^ ^ ^

    Prefix: ^ A ^ B ^ C D

    Key step: End of input — pop the remaining operators ^, ^, ^ to the output.  ·  8 steps. Open in the converter →

  6. Q12Convert A * B % C to postfix

    Show the worked answer

    Postfix: A B * C %

    Prefix: % * A B C

    Key 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.

  1. Q13Convert (A + B) * (C - D) to postfix

    Show the worked answer

    Postfix: A B + C D - *

    Prefix: * + A B - C D

    Key step: Pop - to the output, then discard the matching "(".  ·  12 steps. Open in the converter →

  2. Q14Convert A * (B + C) / D to postfix

    Show the worked answer

    Postfix: A B C + * D /

    Prefix: / * A + B C D

    Key step: Pop * to the output (precedence at least "/"), then push "/".  ·  10 steps. Open in the converter →

  3. Q15Convert ((A + B) * C) - D to postfix

    Show the worked answer

    Postfix: A B + C * D -

    Prefix: - * + A B C D

    Key step: Pop * to the output, then discard the matching "(".  ·  12 steps. Open in the converter →

  4. Q16Convert A + (B * C - D) / E to postfix

    Show the worked answer

    Postfix: A B C * D - E / +

    Prefix: + A / - * B C D E

    Key step: Pop - to the output, then discard the matching "(".  ·  12 steps. Open in the converter →

  5. Q17Convert (A - B) ^ (C + D) to postfix

    Show the worked answer

    Postfix: A B - C D + ^

    Prefix: ^ - A B + C D

    Key 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.

  1. Q18Convert A + B * C - D / E to postfix

    Show the worked answer

    Postfix: A B C * + D E / -

    Prefix: - + A * B C / D E

    Key step: Pop *, + to the output (precedence at least "-"), then push "-".  ·  10 steps. Open in the converter →

  2. Q19Convert A + B * C - (D / E ^ F) * G to postfix

    Show the worked answer

    Postfix: A B C * + D E F ^ / G * -

    Prefix: - + A * B C * / D ^ E F G

    Key step: Pop ^, / to the output, then discard the matching "(".  ·  16 steps. Open in the converter →

  3. Q20Convert K + L - M * N + (O ^ P) * W / U / V * T + Q to postfix

    Show 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 Q

    Key step: Pop *, + to the output (precedence at least "+"), then push "+".  ·  24 steps. Open in the converter →

  4. Q21Convert a + b * c / d - e ^ f ^ g to postfix

    Show the worked answer

    Postfix: a b c * d / + e f g ^ ^ -

    Prefix: - + a / * b c d ^ e ^ f g

    Key step: Pop /, + to the output (precedence at least "-"), then push "-".  ·  14 steps. Open in the converter →

  5. Q22Convert (a + b) * c - (d - e) ^ (f + g) to postfix

    Show the worked answer

    Postfix: a b + c * d e - f g + ^ -

    Prefix: - * + a b c ^ - d e + f g

    Key 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.

  1. Q23Convert 3 + 4 * 2 to postfix

    Show the worked answer

    Postfix: 3 4 2 * +

    Prefix: + 3 * 4 2

    Value: 11

    Key step: End of input — pop the remaining operators *, + to the output.  ·  6 steps. Open in the converter →

  2. Q24Convert (3 + 4) * 2 to postfix

    Show the worked answer

    Postfix: 3 4 + 2 *

    Prefix: * + 3 4 2

    Value: 14

    Key step: Pop + to the output, then discard the matching "(".  ·  8 steps. Open in the converter →

  3. Q25Convert 2 ^ 3 ^ 2 to postfix

    Show the worked answer

    Postfix: 2 3 2 ^ ^

    Prefix: ^ 2 ^ 3 2

    Value: 512

    Key step: End of input — pop the remaining operators ^, ^ to the output.  ·  6 steps. Open in the converter →

  4. Q26Convert 100 / 5 / 2 to postfix

    Show the worked answer

    Postfix: 100 5 / 2 /

    Prefix: / / 100 5 2

    Value: 10

    Key step: Pop / to the output (precedence at least "/"), then push "/".  ·  6 steps. Open in the converter →

  5. Q27Convert 3 + 4 * 2 / (1 - 5) ^ 2 to postfix

    Show the worked answer

    Postfix: 3 4 2 * 1 5 - 2 ^ / +

    Prefix: + 3 / * 4 2 ^ - 1 5 2

    Value: 3.5

    Key step: Pop - to the output, then discard the matching "(".  ·  14 steps. Open in the converter →

  6. Q28Convert 10 % 3 + 2 * 5 to postfix

    Show the worked answer

    Postfix: 10 3 % 2 5 * +

    Prefix: + % 10 3 * 2 5

    Value: 11

    Key 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.

  1. Q29Convert A B + C * back to infix

    Show the worked answer

    Infix: (A + B) * C

    Fully bracketed: ((A + B) * C)

    Prefix: * + A B C

    Open in the converter →

  2. Q30Convert A B C * + back to infix

    Show the worked answer

    Infix: A + B * C

    Fully bracketed: (A + (B * C))

    Prefix: + A * B C

    Open in the converter →

  3. Q31Convert A B C - - back to infix

    Show the worked answer

    Infix: A - (B - C)

    Fully bracketed: (A - (B - C))

    Prefix: - A - B C

    Open in the converter →

  4. Q32Convert a b c ^ ^ back to infix

    Show the worked answer

    Infix: a ^ b ^ c

    Fully bracketed: (a ^ (b ^ c))

    Prefix: ^ a ^ b c

    Open in the converter →

  5. Q33Convert A B ^ C ^ back to infix

    Show the worked answer

    Infix: (A ^ B) ^ C

    Fully bracketed: ((A ^ B) ^ C)

    Prefix: ^ ^ A B C

    Open in the converter →

  6. Q34Convert a b + c d - * back to infix

    Show the worked answer

    Infix: (a + b) * (c - d)

    Fully bracketed: ((a + b) * (c - d))

    Prefix: * + a b - c d

    Open in the converter →

  7. Q35Convert A B C * + D E / - back to infix

    Show the worked answer

    Infix: A + B * C - D / E

    Fully bracketed: ((A + (B * C)) - (D / E))

    Prefix: - + A * B C / D E

    Open in the converter →

Mark-losing mistakes

The five errors that cost the most marks
MistakeShows up asFix
Pushing on equal precedenceA - B - C → A B C - -Pop on equal precedence for every left-associative operator
Treating ^ as left associativea ^ 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 flushOutput ends mid-expressionPop everything left on the stack when the input ends
Showing only the answerFull marks lost on a correct answerWrite 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.

Problems where infix, postfix and the operator stack apply
ProblemWhat it asksConnection
Evaluate Reverse Polish NotationEvaluate a postfix token listExactly the value-stack algorithm
Basic Calculator IIEvaluate infix with + - * /Shunting-yard, or a running stack of terms
Basic CalculatorInfix with brackets and unary minusBracket handling, plus the unary case
Basic Calculator IIIBrackets and all four operatorsFull shunting-yard with an evaluation pass
Build Binary Expression Tree From Infix ExpressionProduce the expression treeSame 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.