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
Have you ever thought about the handling of our files in operating system? Why do we contain a hierarchical file system? How do files saved & deleted under hierarchical directories

Q. Write down an algorithm to add an element in the end of the circular linked list.        A n s . Algo rithm to Add the Element at the End of Circular Linked Lists

Write down any four applications of queues.            Application of Queue (i)  Queue is used in time sharing system in which programs with the similar priority form a queu

For AVL trees the deletion algorithm is a little more complicated as there are various extra steps involved in the deletion of node. If the node is not a leaf node, then it contain

Merge sort: Merge sort is a sorting algorithm that uses the idea of split and conquers. This algorithm splits the array into two halves, sorts them separately and then merges t

Describe Binary Search Tree (BST)? Make a BST for the given sequence of numbers. 45, 36, 76, 23, 89, 115, 98, 39, 41, 56, 69, 48 Traverse the obtained tree in Preorder, Inord

Determination of Time Complexity The RAM Model The random access model (RAM) of computation was devised through John von Neumann to study algorithms. In computer science,

A binary tree is a special tree where each non-leaf node can have atmost two child nodes. Most important types of trees which are used to model yes/no, on/off, higher/lower, i.e.,

Q.1 Write procedures/ Algorithm to insert and delete an element in to array. Q.2. Write an algorithm for binary search. What are the conditions under which sequential search of

Merging 4 sorted files having 50, 10, 25 and 15 records will take time  O (100)