Evaluation of Expressions
Expression evaluation refers to the process of computing the result of a given mathematical or logical expression. Expressions can be written in different forms:
- Infix: Operators are written between operands (e.g.,
A + B
) - Prefix (Polish Notation): Operators are written before operands (e.g.,
+ A B
) - Postfix (Reverse Polish Notation): Operators are written after operands (e.g.,
A B +
)
In the context of expression evaluation, we primarily deal with three types of notations.
✅ 1. Infix Notation (Human-Friendly)
- Format:
A + B
- Operators appear between operands
- Requires parentheses and precedence rules
- Most common for humans
- Harder for machines to parse without conversion
- “parse” means to analyze and understand the structure of the expression.
Example:

✅ 2. Prefix Notation (Polish Notation)
- Format:
+ A B
- Operators come before their operands
- No parentheses needed
- Easy for recursive evaluation
- It means that prefix notation (like
+ A B
) is well-suited for recursive functions — a style of programming where a function calls itself to solve smaller parts of a problem.
- It means that prefix notation (like
Example:

✅ 3. Postfix Notation (Reverse Polish Notation)
- Format:
A B +
- Operators come after operands
- Evaluated using a stack
- Very efficient for machines and calculators
Example:

🧠 Why These 3?
Because any expression (mathematical or logical) can be written and evaluated using infix, prefix, or postfix:
- Humans use infix
- Compilers convert to prefix/postfix
- Machines often use postfix for evaluation using a stack
🔄 Conversion is Always Possible
You can always:
- Convert infix → postfix or prefix
- Evaluate prefix/postfix directly
- Get the same result