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))


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
Using the cohen sutherland. Algorithm. Find the visible portion of the line P(40,80) Q(120,30) inside the window is defined as ABCD A(20,20),B(60,20),C(60,40)and D(20,40)

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

The space-complexity of the algorithm is a constant. It just needs space of three integers m, n and t. Thus, the space complexity is O(1). The time complexity based on the loop

Tree is a widely used data structure employed for representing several problems. We studied tree like a special case of acyclic graph. Though, rooted trees are most prominent of al

A binary search tree is used to locate the number 43. Which of the following probe sequences are possible and which are not? Explain. (a) 61 52 14 17 40 43 (b) 2 3 50 40 60 43 (c)

implement multiple stack in single dimensionl array.write algorithms for various stack operation for them

Q. Write down the binary search algorithm and trace to search element 91 in following given list: 13          30          62           73         81         88             91

Explain the Assertions in Ruby Ruby offers no support for assertions whatever. Moreover, because it's weakly typed, Ruby doesn't even enforce rudimentary type checking on opera

Addition of new records in a Binary tree structure always occurs as leaf nodes, which are further away from the root node making their access slower. If this new record is to be ac

. Create a decision table that describes the movement of inventory