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

ERM, Hi, can you give me a quote for an E-R diagram

Hi, can you give me a quote for an E-R diagram

Define queue fifo ?, A queue is a particular type of collection or abstract...

A queue is a particular type of collection or abstract data type in which the entities in the collection are went in order and the principal functions on the collection are the add

Calculus, basic calculation for algorith.

basic calculation for algorith.

Internal sorting, In internal sorting, all of the data to be sorted is obta...

In internal sorting, all of the data to be sorted is obtainable in the high speed main memory of the computer. We will learn the methods of internal sorting which are following:

Nested for loop, nested for loop for (i = 0; i for (j = 0; j seq...

nested for loop for (i = 0; i for (j = 0; j sequence of statements } } Here, we observe that, the outer loop executes n times. Every time the outer loop execute

Explain memory allocation strategies, Memory Allocation Strategies If i...

Memory Allocation Strategies If it is not desirable to move blocks of due storage from one area of memory to another, it must be possible to relocate memory blocks that have be

Examination, Write an algorithm for binary search. What are its limitations...

Write an algorithm for binary search. What are its limitations? .

Define big oh notation, Big oh notation (O) : The upper bound for the funct...

Big oh notation (O) : The upper bound for the function 'f' is given by the big oh notation (O). Considering 'g' to be a function from the non-negative integers to the positive real

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