Expression trees, Data Structure & Algorithms

What are the expression trees? Represent the below written expression using a tree.

Give a relevant comment on the result that you get when this tree is traversed in Preorder, Inorder and postorder. (a-b) / ((c*d)+e)

The leaves of an expression tree are operands, for instance constants or variable names, and the other nodes include operators. This particular tree happens to be a binary tree, because all of the operations are binary, and although this is the easiest case, it is probable for nodes to have more than two children. It can also be possible for a node to have only one child, as is the case with the unary minus operator. We can evaluate the expression tree, T, by applying the operator at the root of it  to the values obtained by recursively evaluating the left and right subtrees.

The expression tree obtained for the expression: (a - b ) / ( ( c * d ) + e))

1269_expression_tree.png

The traversal of the above drawn expression tree gives the following result:-

Preorder:- ( / - a b + * c d e)

This expression is the same as the "prefix notation" of the original expression.

Inorder:- ( a - b) / ((c * d) + e )

Thus the inorder traversal gives us the actual expression.

Postorder:- ( a b - c d * e + / )

Thus the postorder traversal of this gives us the "posfix notation" or we can say the "Reverse Polish notation" of the original expression.

Posted Date: 7/9/2012 10:28:12 PM | Location : United States







Related Discussions:- Expression trees, Assignment Help, Ask Question on Expression trees, Get Answer, Expert's Help, Expression trees Discussions

Write discussion on Expression trees
Your posts are moderated
Related Questions
Write the algorithm for compound interest

Algorithm for deletion of any element from the circular queue: Step-1: If queue is empty then say "queue is empty" & quit; else continue Step-2: Delete the "front" element

One can change a binary tree into its mirror image by traversing it in Postorder is the only proecess whcih can convert binary tree into its mirror image.

What are the features of an expert system

In what ways we can get the context sensitive F1 help on a field?' Data element documentation. Data element additional text in screen painter. Using the process on help r

Program: Creation of Doubly Linked List OUTPUT Input the values of the element -1111 to come out : 1 Input the values of the element -1111 to come out : 2 Inpu

Q. Define the terms data type and abstract data type. Comment upon the significance of both these.   Ans: We determine the total amount of memory to reserve by determining

What is complexity of an algorithm? What is the basic relation between the time and space complexities of an algorithm? Justify your answer by giving an example.

What is a Spanning tree of a graph? A Spanning Tree is any tree having of vertices of graph tree and some edges of graph is known as a spanning tree.

merging 4 sorted files containing 50 10 25 and 15 records will take time