An algebraic expression is represented as a binary tree with:
- Root: operator
- Left child:
- Right child:
Unambiguous (unlike infix form without parentheses).
Forms
There are 3 common forms of algebraic expressions.
Infix form
The symbol is written in-between the operands. The form we usually use.
Example:
Prefix form
Aka. Polish form. The symbol is written before the operands.
’s prefix form is:
Parentheses are not required. Start solving from right end.
Postfix form
Aka. reverse Polish form. The symbol is written after the operands. Used commonly when parsing algebraic expressions in calculators.
’s prefix form is:
Start solving from left end.