Algorithm to evaluate expression given in postfix notation , Data Structure & Algorithms

Assignment Help:

Q. Write down an algorithm to evaluate an expression given to you in postfix notation. Show the execution of your algorithm for the following given expression.

AB^CD-EF/GH+/+*                                                                               

Ans.

Algorithm to evaluate Post fix Expression is shown as follows

 

Opndstk = the empty stack;

/*scan the input string reading one */

/*element at a time into symb */

while ( not end of input){

symb  = next input character;

if (symb is an operand)

push (opndstk, symb);

else

{

/* symb is an operator */

opnd 2 = Pop (opnd stk);

opnd 1 = Pop (opnd stk);

value = result of applying symb to opnd 1 and opnd 2;

push (opndstk,value);

}/*end else */

}/*end while */

return (pop (opnd stk));

AB^CD-EF/GH+/+*

Symb

Opnd1

Opnd2

Value

Opndstk

A

 

 

 

A

B

 

 

 

A,B

^

A

B

A^B

A^B

C

A

B

A^B

A^B,C

D

A

B

A^B

A^B,C,D

-

C

D

C-D

A^B,C-D

E

C

D

C-D

A^B,C-D,E

F

C

D

C-D

A^B,C-D,E,F

/

E

F

E/F

A^B,C-D,E/F

G

E

F

E/F

A^B,C-D,E/F,G

H

E

F

E/F

A^B,C-D,E/F,G,H

+

G

H

G+H

A^B,C-D,E/F,G+H

/

E/F

G+H

(E/F)/(G+H)

A^B,C-D, (E/F) /(G+H)

+

C-D

(E/F)/(G+H)

(C-D)+(E/F)/(G+H)

A^B,(C-D)+

(E/F)/(G+H)

*

A^B

(C-

D)+(E/F)/(G+H)

A^B*((C-D)+

(E/F)/(G+H))

A^B*((C-D)+

(E/F)/(G+H))


Related Discussions:- Algorithm to evaluate expression given in postfix notation

Inorder traversal, Inorder traversal: The left sub tree is visited, then t...

Inorder traversal: The left sub tree is visited, then the node and then right sub-tree. Algorithm for inorder traversal is following: traverse left sub-tree visit node

The best average behaviour, The best average behaviour is shown by  Qui...

The best average behaviour is shown by  Quick Sort

Applications of linear and binary search, The searching method are applicab...

The searching method are applicable to a number of places in current's world, may it be Internet, search engines, text pattern matching, on line enquiry, finding a record from data

Tree Traversal, If preorder traversal and post order traversal is given the...

If preorder traversal and post order traversal is given then how to calculate the pre order traversal. Please illustrate step by step process

Dataset for dmi, The following DNA sequences are extracted from promoter re...

The following DNA sequences are extracted from promoter region of genes which are co-regulated by the same transcription factor (TF). The nucleotide segments capitalized in the giv

Explain about franklin algorithm, Explain about Franklin Algorithm We m...

Explain about Franklin Algorithm We mentioned how the number of possible comparisons of polygons grows as the square of the number of polygons in the scene. Many of the hidden-

Define game trees, Game trees An interesting application of trees is th...

Game trees An interesting application of trees is the playing of games such as tie-tac-toe, chess, nim, kalam, chess, go etc. We can picture the sequence of possible moves by m

A binary tree of depth "d" is an almost complete binary tree, A binary tree...

A binary tree of depth "d" is an almost complete binary tree if  A) Every leaf in the tree is either at level "d" or at level "d-1"  B)  For any node "n" in the tree with a

Memory allocation strategies, Q. Explain the various memory allocation stra...

Q. Explain the various memory allocation strategies.                                                            Ans. M e m ory Allocation Strategies are given as follow

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd