Note: Do not use spaces in expression. A+B/C or 4+5/3
not A + B / C or 4 + 5 / 3

Updated (26 Feb 2023)

Infix -> Postfix & Prefix

This is a simple infix to prefix or postfix Converter.


Enter the Infix expression below in box and press Convert

Postfix : | Prefix :

By Raj

Sr. no. Expression Stack Postfix

Algorithm used

Postfix

  • Step 1: Add ")" to the end of the infix expression
  • Step 2: Push "(" onto the stack
  • Step 3: Repeat until each character in the infix notation is scanned
    • 3.1: IF a "(" is encountered, push it on the stack
    • 3.2: IF an operand ( whether a digit or a character) is encountered, add it postfix expression.
    • 3.3: IF a ")" is encountered, then
      a. Repeatedly pop from stack and add it to the postfix expression until a "(" is encountered.
      b. Discard the "(". That is, remove the(from stack and do not add it to the postfix expression
    • 3.4: IF an operator O is encountered, then
      a. Repeatedly pop from stack and add each operator ( popped from the stack) to the postfix expression which has equal or higher precedence than O
      b. Push the operator O to the stack.
    [END OF IF]
  • Step 4: Repeatedly pop from the stack and add it to the postfix expression until the stack is empty
  • Step 5: EXIT

Prefix

  • Step 1: Reverse the infix string. Note that while reversing the string you must interchange left and right parentheses.
  • Step 2: Obtain the postfix expression of the expression obtained from Step 1 using the above given postfix algorithm with slight change in Step 3.4

    IF an operator O is encountered, then
    a. Repeatedly pop from stack and add each operator ( popped from the stack) to the postfix expression which has equal or higher precedence than O
  • Step 3: Reverse the postfix expression to get the prefix expression

Understanding the Infix to Postfix & Prefix Converter

Our Infix to Postfix & Prefix Converter is a powerful tool designed to transform mathematical expressions between different notations. This converter is particularly useful for students, programmers, and anyone working with expression parsing or compiler design.

What are Infix, Postfix, and Prefix Notations?

How to Use the Converter

  1. Enter your infix expression in the input box. Remember not to use spaces between characters.
  2. Valid formats include:
    • Numeric expressions: 2+4/5*(5-3)^5^4
    • Algebraic expressions: A+B/C*(D-A)^F^H
  3. Click the "Convert" button to see the postfix and prefix equivalents.
  4. Review the conversion tables to understand the step-by-step process.

Features of Our Converter

Why Use Different Notations?

While infix notation is more readable for humans, postfix and prefix notations have several advantages:

Applications

This converter is valuable for:

By using this tool and studying the conversion process, you can gain a deeper understanding of how mathematical expressions are structured and processed in different notations. This knowledge is fundamental in various areas of computer science and mathematics.

function sel(x) { return document.getElementById(x) } $("#fullresult").hide(); function convert() { const input = document.getElementById("expression").value.trim(); document.getElementById("postfix").innerHTML = infixToPostfix(input)['postfixExpression']; document.getElementById("prefix").innerHTML = infixToPrefix(input)['prefixExpression']; } //converter button and expression $("button#convert").click(function () { convert(); var items, tab = ""; $("#fullresult").show(); const input = document.getElementById("expression").value.trim(); switch ($('input[name=fixer]:checked').val()) { case '1': items = infixToPostfix(input, 1)['table']; sel("itemname").innerHTML = "Postfix"; $("#ifpre").html("Below is the table showing the conversion steps."); break; case '2': items = infixToPrefix(input, 1)['table']; sel('itemname').innerHTML = "Prefix ( Reversed )"; $("#ifpre").html("1. Reversed the Infix expression along with swithing ( with ) and vice versa.
2. Find the Postfix Expression as below table.
3. Reverse the resultant expression like in step 1."); break; } for (var i = 0; i < items.exp.length; i++) { tab +="" + i + "" + items['exp'][i] + "" + items['stack'][i] + "" + items['conexp'][i] + "" ; } sel("tabledata").innerHTML=tab; }) //evaluator button and expression