SlideShare a Scribd company logo
DATA STRUCTURES
USING
‘C’
Evaluation

Of
Postfix
Evaluation

Of
Postfix
-BY AKHIL AHUJA
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)
Precedence of operators:
1. ‘$’ or ‘^’

Highest Precedence

2. ‘*’ and ‘/’

High Precedence

3. ’+’ and ‘-’

Low Precedence

4. ‘=‘

Lower Precedence

5. ‘(‘ and ‘)’

Lowest Precedence
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 ‘)’
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.
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.
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)

-
Here’s an another example
4

3

*

6

7

+ 5 -

+

)
4

3

*

6

7

+ 5 -

+

)

Push the opening bracket ‘(‘ into the stack .

STACK
4

(
STACK

3

*

6

7

+ 5 -

+

Operand ‘4’ push it into the stack

)
4

3

4
(
STACK

*

6

7

+ 5 -

+

)

Operand ‘3’ push it into the stack.
4

3

*

3
4
(
STACK

6

7

+ 5 -

Now comes Operator ‘*’

+

)
4

3

*

6

7

+ 5 -

*

3
4
(
STACK

Pop operand ‘3’ and ‘4’

+

)
4

3

*

6

7

+ 5 -

4* 3

(
STACK

Evaluate the expression
4*3 =12
Pus it into the stack

+

)
4

3

*

6

7

+ 5 -

4* 3

(
STACK

Evaluate the expression
4*3 =12

+

)
4

3

*

6

7

+ 5 -

4 * 3 12

Push it into the stack

(
STACK

+

)
4

3

*

6

7

+ 5 -

+

Operand ‘6’ push it into the
stack

12
(
STACK

)
4

3

*

6

Operand ‘7’ push it into the
stack

7 +
7

6
12
(
STACK

5

-

+

)
4

3

*

6

7

+ 5 -

Operand ‘7’ and ‘6’
Are popped

Operand ‘+’ push it into the
stack

7
6
12
(
STACK

+

)
4

3

*

6

7

+ 5 6+7

Evaluate ‘6+7’
=13

12
(
STACK

+

)
4

3

*

6

7

+ 5 13

Push it into the stack

12
(
STACK

+

)
4

3

*

6

7

Operand ‘5’ push it into the stack

5
+ 5 -

13

12
(
STACK

+

)
4

3

*

6

Operands ‘5’ and ‘13’ are
popped

7

+ 5 - + )

5
13

Now operator ‘-’ occurs

12
(
STACK
4

3

*

6

7

+ 5 -

Evaluating “13-5”
We get ‘8’

12
(
STACK

+

)
4

3

*

6

7

+ 5 8

Now, push the resultant value i.e ‘8’
in the stack

12
(
STACK

+

)
4

3

*

Operator ‘+’

6

7

+ 5 -

+ )

8

12
(
STACK
4

3

*

6

7

+ 5 -

+

12 + 8
By Evaluating , we get

20
(
STACK

)
4

3

*

6

7

+ 5 -

+

20
So push ‘20’ in stack

(
STACK

)
4

3

*

6

Now atlast ‘)’ occurs
Now , pop the element till
the opening bracket

7

+ 5 -

+ )

20
(
STACK
4

3

*

6

7

+ 5 -

20

+

)

)

(
STACK
4

3

*

6

7

+ 5 -

+

)

20
Now push the element

AND THE FINAL ANSWRER IS ’20’
()
STACK
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression
Evaluation of postfix expression

More Related Content

PPTX
Evaluation of postfix expression using stack
PPTX
Stack_Data_Structure.pptx
PPT
Stacks
PPTX
The Stack And Recursion
PPT
PPTX
Introduction to stack
PDF
Linked list implementation of Queue
PPT
Expression evaluation
Evaluation of postfix expression using stack
Stack_Data_Structure.pptx
Stacks
The Stack And Recursion
Introduction to stack
Linked list implementation of Queue
Expression evaluation

What's hot (20)

PDF
Applications of stack
PPTX
Linked list
PPTX
stack & queue
PPTX
RECURSIVE DESCENT PARSING
PPTX
queue & its applications
PPTX
Instruction codes
PPTX
Top Down Parsing, Predictive Parsing
PPTX
STACKS IN DATASTRUCTURE
PPTX
Stack and its operations
PPTX
Queue ppt
PPT
Top down parsing
PPSX
PPSX
Stacks Implementation and Examples
PPTX
PPT
PPTX
Presentation on Breadth First Search (BFS)
PPTX
Booth’s algorithm.(a014& a015)
PDF
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
PPT
Fundamentals of data structures
PPTX
Timing and control
Applications of stack
Linked list
stack & queue
RECURSIVE DESCENT PARSING
queue & its applications
Instruction codes
Top Down Parsing, Predictive Parsing
STACKS IN DATASTRUCTURE
Stack and its operations
Queue ppt
Top down parsing
Stacks Implementation and Examples
Presentation on Breadth First Search (BFS)
Booth’s algorithm.(a014& a015)
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Fundamentals of data structures
Timing and control
Ad

Viewers also liked (20)

DOC
Infix to-postfix examples
DOCX
Conversion from infix to prefix using stack
PDF
computer notes - Evaluating postfix expressions
PPTX
Infix to postfix conversion
PDF
Infix prefix postfix expression -conversion
PDF
Infix to Prefix (Conversion, Evaluation, Code)
PPTX
Infix to postfix
PPT
Conversion of Infix To Postfix Expressions
PPT
Stack Data Structure & It's Application
PDF
The Double Helix - Spaced Learning
PDF
02 stackqueue
PPTX
5.stack
PDF
Expression trees
PDF
C applications
PPT
Computer notes - Expression Tree
PPTX
8.binry search tree
PDF
Polish nootation
PPT
PPT
01 stack 20160908_jintaek_seo
PDF
Time complexity (linear search vs binary search)
Infix to-postfix examples
Conversion from infix to prefix using stack
computer notes - Evaluating postfix expressions
Infix to postfix conversion
Infix prefix postfix expression -conversion
Infix to Prefix (Conversion, Evaluation, Code)
Infix to postfix
Conversion of Infix To Postfix Expressions
Stack Data Structure & It's Application
The Double Helix - Spaced Learning
02 stackqueue
5.stack
Expression trees
C applications
Computer notes - Expression Tree
8.binry search tree
Polish nootation
01 stack 20160908_jintaek_seo
Time complexity (linear search vs binary search)
Ad

Similar to Evaluation of postfix expression (20)

PPT
MO 2020 DS Stacks 3 AB.ppt
PPTX
Lecture_04.2.pptx
PPTX
Data structures (Infix, Prefix and Postfix notations).pptx
PPTX
STACK APPLICATIONS: INFOX TO POSTFIX CONVERSION AND EVALUATION OF POSTFIX EXP...
PDF
Evaluation of Postfix Expression-Concept and Example
PPTX
Lect-5 & 6.pptx
PPTX
DS UNIT1_STACKS.pptx
PPSX
Data structure_Stack Introduction & app.
PPTX
Unit 2 application of stack
PPTX
Evaluation of prefix expression with example
PPT
Computer notes - Postfix
PPTX
STACK USING LISTS.pptx
PPT
computer notes - Data Structures - 7
PPTX
COMP1603 Stacks and RPN 2023 Recording (2).pptx
PPTX
Data strutcure and annalysis topic stack
PPTX
week9-prefixinfixandpostfixnotations-191013065821.pptx
PPTX
Prefix, Infix and Post-fix Notations
PDF
stack-111104232459-phpapp02.pdf
PPT
Arithmetic notation conversion infix to1
MO 2020 DS Stacks 3 AB.ppt
Lecture_04.2.pptx
Data structures (Infix, Prefix and Postfix notations).pptx
STACK APPLICATIONS: INFOX TO POSTFIX CONVERSION AND EVALUATION OF POSTFIX EXP...
Evaluation of Postfix Expression-Concept and Example
Lect-5 & 6.pptx
DS UNIT1_STACKS.pptx
Data structure_Stack Introduction & app.
Unit 2 application of stack
Evaluation of prefix expression with example
Computer notes - Postfix
STACK USING LISTS.pptx
computer notes - Data Structures - 7
COMP1603 Stacks and RPN 2023 Recording (2).pptx
Data strutcure and annalysis topic stack
week9-prefixinfixandpostfixnotations-191013065821.pptx
Prefix, Infix and Post-fix Notations
stack-111104232459-phpapp02.pdf
Arithmetic notation conversion infix to1

Recently uploaded (20)

PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Trump Administration's workforce development strategy
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
Lesson notes of climatology university.
PPTX
master seminar digital applications in india
PPTX
History, Philosophy and sociology of education (1).pptx
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
A systematic review of self-coping strategies used by university students to ...
Anesthesia in Laparoscopic Surgery in India
Supply Chain Operations Speaking Notes -ICLT Program
Microbial disease of the cardiovascular and lymphatic systems
Trump Administration's workforce development strategy
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Orientation - ARALprogram of Deped to the Parents.pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
Lesson notes of climatology university.
master seminar digital applications in india
History, Philosophy and sociology of education (1).pptx
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Weekly quiz Compilation Jan -July 25.pdf
Paper A Mock Exam 9_ Attempt review.pdf.
Chinmaya Tiranga quiz Grand Finale.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf

Evaluation of postfix expression