
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is Postfix Notation
In postfix notation, the operator appears after the operands, i.e., the operator between operands is taken out & is attached after operands.
Example1 − Translate a ∗ d − (b + c) into Postfix form.
Solution
ad ∗ bc + −
Example2 − Convert a + (b ∗? c) is in Postfix form.
Solution
Here ? represents the unary minus operator.
a b c ? ∗ +
Example3 − Convert Postfix Expression into Infix Expression using Stack Implementation
a d ∗ bc + −
Solution
String Symbols | Stack |
---|---|
ad ∗ bc + − | |
A | A |
D | ad |
* | (a * d) |
B | (a * d)b |
C | (a * d)b c |
+ | (a ∗ d)(b + c) |
- | (a ∗ d)-(b + c) |
Example4 − Calculate the value for the postfix expression.
57 + 2 ∗ 3/
Solution
This expression can be evaluated by using a stack. Each symbol can be inserted sequence wise & the operator can be applied on operands lying at the top of the stack and next to it.
Symbol | Stack | Description |
---|---|---|
5 | 5 | |
7 | 5 7 | 5 + 7 |
+ | 12 | |
2 | 12 2 | |
* | 24 | 12 * 2 |
3 | 24 3 | |
/ | 8 | 24/3 |
∴ Answer is 8.
Postfix Notations used in Control Statements
- Jump − Jump to label ? can be written in postfix notations as −
?jump
-
jlt (Jump if less than) − e1 e2 ? jlt makes the jump to label if e1 has a smaller value than e2.
-
jeqz (jump if equal to zero) − e ? jeqz causes jump to ? if e has the value zero.
Example5 − Convert the following statement into postfix Notation.
if e then x else y
Solution
If − else statement can be written as
If e then
x
else
?1: y
?2: exit
The postfix Notation will be
Example6 − Convert expression into Postfix Notation.
if a then if c + d then a + c else a * c else a + b.
Solution
It can be written as
if a then
if c + d then
a + c
else
a * c
?1:
else
?2: a + b
?3: exit