Question: Programming Languages Lab 2 Infix, Postfix and Prefix While we use infix expressions in our day to day lives. Computers have trouble understanding this format
Programming Languages Lab
Infix, Postfix and Prefix
While we use infix expressions in our day to day lives. Computers have
trouble understanding this format because they need to keep in mind rules
of operator precedence and also brackets. Prefix and Postfix expressions
are easier for a computer to understand and evaluate.
Infix Postfix and Prefix notations are three different but equivalent ways of
writing expressions. It is easiest to demonstrate the differences by looking
at examples of operators that take two operands.
Given two operands a and b and an operator the infix notation implies
that will be placed in between a and b ie a b When the operator is
placed after both operands ie ab it is called postfix notation. And when
the operator is placed before the operands ie a b the expression in
prefix notation.
Infix notation: X Y
Operators are written inbetween their operands. This is the usual way we
write expressions. An expression such as A B C D is usually taken to
mean something like: "First add B and C together, then multiply the result
by A then divide by D to give the final answer."
Postfix notation also known as "Reverse Polish notation": X Y
Operators are written after their operands. The infix expression given
above is equivalent to A B C D
Prefix notation also known as "Polish notation": X Y
Operators are written before their operands. The expressions given above
are equivalent to A B C D
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
