evaluation of postfix expression
Data Structure Notes

Evaluation of Postfix Expression Examples

Evaluation of Postfix Expression

Evaluation of Postfix Expression using Stack is an important topic in Data Structure for AKTU Data Structure Exam.

Problem solving questions based on evaluation of postfix expression is generally asked in various university examination and also in competitive examination such as GATE and UGC NET.

Today in this tutorial we will learn about the step wise step process used to evaluate the value of postfix expression with example.

Algorithm for Evaluation of Postfix Expression

The postfix expression is evaluated easily by the use of a Stack.

Step 1 – Scan the given postfix expression from left to right till end.

Step 2. If scanned symbol is a number or operand is seen, it is pushed onto the stack.

Step 3. When an operator is occurred, the operator is applied to the two numbers that are popped from the stack and the result is pushed onto the stack.

Step 4. When an expression is given in postfix notation, there is no need to know any precedence rules; this is our obvious advantage.

Example 1

Evaluate the Given Postfix Expression 6 5 2 3 + 8 * + 3 + *

Solution 

Step wise step solution of the above questions is given below

evaluation of postfix expression

Final value of given postfix expression is 288

Example 2 – Evaluate the value of following postfix expression

 6 2 3 + – 3 8 2 / + * 2 ^ 3 +

Solution – Solution of the above question is given below

postfix evaluation

Final value of given postfix expression is 52

Important Point to remember 

During evaluating postfix expression important point  to remember is that be careful whenever we are going to pop two operands   the  which is going to be operand 1 and which is going to be operand 2 .

In case of * and + it does not make a difference but in case of / , – it create a difference. So remember the following rule whenever pop or remove two operands or elements from stack the element or operand which is removed first will be operand 2 and second pop out element will be operand 1.

Now perform Operand 1 Operator Operand 2 and push the  result on Stack.

 Evaluation of Postfix Expression Problems

Some more problems based on Evaluating the Postfix expression are solved in the pictures.

We used algorithm as discussed above to evaluate the postfix expression.

evaluation postfix expression

evaluating postfix

postfixevalution

Conclusion and Summary

In this tutorial we have discussed the evaluation of postfix expression with examples.

I hope this tutorial will be beneficial for computer science students. After reading this tutorial students can easily solve the problems related to evaluation of postfix expression.

Leave a Reply

Your email address will not be published. Required fields are marked *