Infix to Prefix Visualizer

What is Prefix Notation?

Prefix notation (also called Polish Notation) is a way of writing expressions where the operator comes before the operands.

For example, the infix expression 3 + 4 becomes + 3 4 in prefix.
It removes the need for parentheses by using operator order directly.

Infix to Prefix Conversion Steps

  1. Reverse the infix expression, while keeping the positions of parentheses correct.
  2. Replace '(' with ')' and vice-versa.
  3. Convert the reversed expression to postfix using a stack.
  4. Finally, reverse the postfix expression to get the prefix expression.

Example:
Infix: (A + B) * (C - D)
Step 1: Reverse → (D - C) * (B + A)
Step 2: Convert to postfix → D C - B A + *
Step 3: Reverse → * + A B - C D

Operator Precedence Table

OperatorMeaningPrecedence
( )ParenthesesHighest
^Exponentiation2
* /Multiplication / Division3
+ -Addition / Subtraction4 (Lowest)

Note: Higher precedence means the operation will happen first. Exponentiation (^) is evaluated right-to-left, while others are left-to-right.

Visualize the conversion from infix to prefix notation

Conversion Status

Enter an infix expression and click Convert

Stack

Stack is empty

Output

Output will appear here

Explore other conversions