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

State the term access restrictions - container, What is Access Restriction...

What is Access Restrictions Structured containers with access restrictions only allow clients to add, remove and examine elements at certain locations in their structure. For

Explain what is stack. describe ways to execute stack. , ST AC K is ...

ST AC K is explained as follows : A stack is one of the most usually used data structure. A stack is also called a Last-In-First-Out (LIFO) system, is a linear list in

Procedure to delete all terminal nodes of the tree, Q. Let a binary tree 'T...

Q. Let a binary tree 'T' be in memory. Write a procedure to delete all terminal nodes of the tree.       A n s . fun ction to Delete Terminal Nodes from Binary Tree

Asymptotic analysis, Asymptotic Analysis Asymptotic analysis is dependi...

Asymptotic Analysis Asymptotic analysis is depending on the idea that as the problem size grows, the complexity can be defined as a simple proportionality to some known functio

Computational complexity, Generally, Computational complexity of algorithms...

Generally, Computational complexity of algorithms are referred to through space complexity (space needed for running program) and time complexity (time needed for running the progr

Searching techniques, Searching is the procedure of looking for something. ...

Searching is the procedure of looking for something. Searching a list containing 100000 elements is not the similar as searching a list containing 10 elements. We discussed two sea

Red black tree, red black tree construction for 4,5,6,7,8,9

red black tree construction for 4,5,6,7,8,9

Advanced data structures - splay trees, This is a unit of which targeted on...

This is a unit of which targeted on the emerging data structures. Red- Black trees, Splay trees, AA-trees & Treaps are introduced. The learner must explore the possibilities of app

Endogenous model, Question a) Describe how the endogenous model is an ...

Question a) Describe how the endogenous model is an improvement to the neo-classical model in explaining the long-run effect of investment on economic growth of a country.

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