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

Time Complexity: O(n)

Space Complexity: O(n)

Infix to Prefix

intermediate

Converts standard infix expressions to prefix (Polish) notation using reversal and the Shunting-Yard algorithm.

Original:(a+b)*c→ reversed + swap parens →c*(b+a)
Compares0
Init
empty
Operator Stack
i
c
[0]
*
[1]
(
[2]
b
[3]
+
[4]
a
[5]
)
[6]
Output Buffer
empty
Initialize: infix="(a+b)*c". We will reverse+swap parens to get modified expression.