Postfix to Infix Visualization & Animation
Converts postfix to infix by wrapping each operator application in parentheses using a stack; O(n).
## What is it?
Convert a postfix expression (e.g. `AB+C*`) back to infix notation (e.g. `(A+B)*C`). Parentheses must be added to preserve the correct operator precedence.
## How it works
- Scan postfix left to right using a stack
- **Operand** → push to stack
- **Operator** → pop two operands (`op2`, then `op1`), form `(op1 operator op2)` with parentheses, push the result back
- At the end, the stack holds the infix expression
## When to use
- Human-readable expression conversion
- Displaying compiler intermediate representation in a readable form
## Key Points
- Always wrap in parentheses when forming a sub-expression to avoid ambiguity
- Pop order matters: second pop is `op1` (left operand), first pop is `op2` (right operand)
- O(n) time and space
Category: algorithms
Difficulty: intermediate
- expression-evaluation
- stack
Time Complexity: O(n)
Space Complexity: O(n)
View Postfix to Infix Visualization