Infix to Postfix Visualization & Animation
Converts infix expressions to Reverse Polish Notation using Dijkstra's Shunting-Yard algorithm; O(n).
## What is it?
Convert an infix expression (standard math notation, e.g. `A+B*C`) to postfix notation (e.g. `ABC*+`) also known as Reverse Polish Notation (RPN). Postfix is easier for computers to evaluate.
## How it works
**Shunting-Yard Algorithm (Dijkstra):**
- Scan left to right
- **Operand** → output it
- **Operator** → pop operators from the stack to output while they have higher or equal precedence, then push current
- **`(`** → push to stack
- **`)`** → pop to output until `(` is found; discard both parentheses
- At the end, pop all remaining operators from stack to output
## When to use
- Expression evaluation without parentheses
- Calculator implementations
- Compiler intermediate representation
## Key Points
- Postfix evaluation: push operands, pop two on operator, push result
- Precedence: `*`, `/` > `+`, `-`; `^` is right-associative
- No parentheses in output — operator ordering handles precedence implicitly
Category: algorithms
Difficulty: intermediate
- expression-evaluation
- stack
Time Complexity: O(n)
Space Complexity: O(n)
View Infix to Postfix VisualizationInfix to Postfix
intermediateConverts infix expressions to Reverse Polish Notation using Dijkstra's Shunting-Yard algorithm; O(n).
Compares0
Init
empty
Operator Stack
i
(
[0]a
[1]+
[2]b
[3])
[4]*
[5]c
[6]Output Buffer
empty
Initialize: infix="(a+b)*c". Scan left to right.
1 / 19