Your SlideShare is downloading. ×
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Evaluation of postfix expression

901

Published on

this is just to explain how expression is converted from postfix to infix in data structure

this is just to explain how expression is converted from postfix to infix in data structure

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
901
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
54
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. DATA STRUCTURES USING ‘C’
  • 2. Evaluation Of Postfix
  • 3. Evaluation Of Postfix -BY AKHIL AHUJA
  • 4. What is Postfix expression?  IF THE OPERATOR SYMBOLS ARE PLACED AFTER ITS OPERANDS , THEN THE EXPRESSION IS IN POSTFIX NOTATION.  Postfix expression is also known as Reverse Polish Notation(RPN). In RPN the operators follow their operands.  Despite the name , Reverse Polish Notation is not exactly the reverse of polish notation , for the operands they are still written in conventional manner. For eg : “*63”in polish notation and “63*” in reverse polish notation. In this , expression is different but the answer is same (i.e 18)
  • 5. Precedence of operators: 1. ‘$’ or ‘^’ Highest Precedence 2. ‘*’ and ‘/’ High Precedence 3. ’+’ and ‘-’ Low Precedence 4. ‘=‘ Lower Precedence 5. ‘(‘ and ‘)’ Lowest Precedence
  • 6. Fundamental principles followed while evaluating the postfix expression : 1.Read the expression from left to right. 2.If there comes an operand , push it into the stack. 3.If there comes an operator , pop operand 1 and operand 2 and then : A . Push ‘(‘ B . Push ‘operand 2’ C . Push ‘operator’ D . Push ‘operand 1’ E . Push ‘)’
  • 7. Advantages of Postfix Expression:  (A). Postfix notation is easier to work with. In a postfix expression operators operands appear before the operators, there is no need of operator precedence and other rules. In postfix expression the topmost operands are popped off and operator is applied and the result is again pushed to the stack and thus finally the stack contains a single value at the end of the process.  (B). In postfix expression, there are no parentheses and therefore the order of evaluation will be determined by the positions of the operators and related operands in the expression.
  • 8. Algorithm for Postfix Expression : 1.Read the element. 2.If element is an operand then: Push the element into the stack. 3.If element is an operator then : Pop two operands from the stack. Evaluate expression formed by two operand and the operator. Push the result of expression in the stack end. 4.If no more elements then: Pop the result Else Goto step 1.
  • 9. How to evaluate postfix (manually) Going from left to right, if you see an operator, apply it to the previous two operands (numbers) Example: A B C * D / + E (B*C) ((B*C)/D) (A+(B*C)/D) ((A+(B*C)/D)-(E-F)) Equivalent infix: A+ B * C / D– (E– F) F - (E – F) -
  • 10. Here’s an another example
  • 11. 4 3 * 6 7 + 5 - + )
  • 12. 4 3 * 6 7 + 5 - + ) Push the opening bracket ‘(‘ into the stack . STACK
  • 13. 4 ( STACK 3 * 6 7 + 5 - + Operand ‘4’ push it into the stack )
  • 14. 4 3 4 ( STACK * 6 7 + 5 - + ) Operand ‘3’ push it into the stack.
  • 15. 4 3 * 3 4 ( STACK 6 7 + 5 - Now comes Operator ‘*’ + )
  • 16. 4 3 * 6 7 + 5 - * 3 4 ( STACK Pop operand ‘3’ and ‘4’ + )
  • 17. 4 3 * 6 7 + 5 - 4* 3 ( STACK Evaluate the expression 4*3 =12 Pus it into the stack + )
  • 18. 4 3 * 6 7 + 5 - 4* 3 ( STACK Evaluate the expression 4*3 =12 + )
  • 19. 4 3 * 6 7 + 5 - 4 * 3 12 Push it into the stack ( STACK + )
  • 20. 4 3 * 6 7 + 5 - + Operand ‘6’ push it into the stack 12 ( STACK )
  • 21. 4 3 * 6 Operand ‘7’ push it into the stack 7 + 7 6 12 ( STACK 5 - + )
  • 22. 4 3 * 6 7 + 5 - Operand ‘7’ and ‘6’ Are popped Operand ‘+’ push it into the stack 7 6 12 ( STACK + )
  • 23. 4 3 * 6 7 + 5 6+7 Evaluate ‘6+7’ =13 12 ( STACK + )
  • 24. 4 3 * 6 7 + 5 13 Push it into the stack 12 ( STACK + )
  • 25. 4 3 * 6 7 Operand ‘5’ push it into the stack 5 + 5 - 13 12 ( STACK + )
  • 26. 4 3 * 6 Operands ‘5’ and ‘13’ are popped 7 + 5 - + ) 5 13 Now operator ‘-’ occurs 12 ( STACK
  • 27. 4 3 * 6 7 + 5 - Evaluating “13-5” We get ‘8’ 12 ( STACK + )
  • 28. 4 3 * 6 7 + 5 8 Now, push the resultant value i.e ‘8’ in the stack 12 ( STACK + )
  • 29. 4 3 * Operator ‘+’ 6 7 + 5 - + ) 8 12 ( STACK
  • 30. 4 3 * 6 7 + 5 - + 12 + 8 By Evaluating , we get 20 ( STACK )
  • 31. 4 3 * 6 7 + 5 - + 20 So push ‘20’ in stack ( STACK )
  • 32. 4 3 * 6 Now atlast ‘)’ occurs Now , pop the element till the opening bracket 7 + 5 - + ) 20 ( STACK
  • 33. 4 3 * 6 7 + 5 - 20 + ) ) ( STACK
  • 34. 4 3 * 6 7 + 5 - + ) 20 Now push the element AND THE FINAL ANSWRER IS ’20’ () STACK

×