Infix to Prefix Visualization & Animation
Converts standard infix expressions to prefix (Polish) notation using reversal and the Shunting-Yard algorithm.
## What is it?
Convert an infix expression (operators between operands, e.g. `A+B`) to prefix notation (operator before operands, e.g. `+AB`) also known as Polish Notation. Prefix notation eliminates the need for parentheses.
## How it works
- Reverse the infix expression and swap `(` with `)` and vice versa
- Apply the Infix → Postfix algorithm on the modified string
- Reverse the resulting postfix string to get the prefix expression
**Alternative direct algorithm:**
- Scan right to left; use a stack for operators
- Operands go directly to output
- Operators: pop operators with **greater** precedence (not equal, unlike postfix) before pushing
## When to use
- Compiler design and expression parsing
- Understanding operator precedence and associativity
- Building expression trees
## Key Points
- Prefix (Polish) notation: operator comes first, e.g., `+AB`, `*+ABC`
- No parentheses needed — order is unambiguous
- Right-to-left scan; right-associative operators need careful handling
Category: algorithms
Difficulty: intermediate
- expression-evaluation
- stack
Time Complexity: O(n)
Space Complexity: O(n)
View Infix to Prefix Visualization