Prefix and Postfix Expressions, Data Structure & Algorithms

Q. Draw the expression tree of the infix expression written below and then convert it intoPrefix and Postfix expressions.

((a + b) + c * (d + e) + f )* (g + h )

Ans:

The expression given is:

 

189_Prefix and postfix expression.png

 

The postfix expression obtained is:

((a+b)+c*(d+e)+f)*(g+h)

= ((ab+)+c*(de+)+f)*(gh+)

= ((ab+)+(cde+*)+f)*(gh+)

= ((ab+cde+*+)+f)*(gh+)

= (ab+cde+*+f+)*(gh+)

=(ab+cde+*+f+gh+*)

The prefix expression obtained is:

((a+b)+c*(d+e)+f)*(g+h)

= ((+ab)+c*(+de)+f)*(+gh)

= ((+ab)+(*c+de)+f)*(+gh)

= ((++ab*c+de)+f)*(+gh)

= (+++ab*c+def)*(+gh)

= (*+++ab*c+def+gh)

 

Posted Date: 7/10/2012 3:47:37 AM | Location : United States







Related Discussions:- Prefix and Postfix Expressions, Assignment Help, Ask Question on Prefix and Postfix Expressions, Get Answer, Expert's Help, Prefix and Postfix Expressions Discussions

Write discussion on Prefix and Postfix Expressions
Your posts are moderated
Related Questions
implement multiple stack in single dimensionl array.write algorithms for various stack operation for them

In order to get the contents of a Binary search tree in ascending order, one has to traverse it in In-order

Comparison of Gouraud and Phong Shading Phong shading requires more calculations, but produces better results for specular reflection than Gouraud shading in the form of more r

what is the difference between data type and abstract data type

implement multiple stacks in a single dimensional array. write algorithm for various stack operation for them

Merging 4 sorted files having 50, 10, 25 and 15 records will take time

What are the Dynamic arrays Dynamic arrays are convenient for programmers since they can never be too small-whenever more space is needed in a dynamic array, it can simply be e

Postorder traversal of a binary tree struct NODE { struct NODE *left; int value;     /* can take any data type */ struct NODE *right; }; postorder(struct NODE

What is algorithm's Optimality? Optimality  is  about  the  complexity  of  the  problem  that  algorithm  solves.  What  is  the  minimum amount  of  effort  any  algorithm  w

what is frequency count with examble