Draw the tree structure for the following expression : [a+(b-c)]*[(d-e)/(f+g-h)]
Draw the tree structure for the following expression :
[a+(b-c)]*[(d-e)/(f+g-h)]
Draw the tree structure for the following expression :
[a+(b-c)]*[(d-e)/(f+g-h)]
Best answer
The root is *; its left subtree is a + (b − c) and its right subtree is (d − e) / ((f + g) − h).
*
/ \
+ /
/ \ / \
a - - -
/ \ / \ / \
b c d e + h
/ \
f g
How it is built:
* between the two square brackets, so it is the root.a + (b − c): + with left child a and right child the subtree b − c./ with left child d − e. Its right child is f + g − h, which is evaluated left to right as (f + g) − h, so − is the parent with children f + g and h.Every operator is an internal node with exactly two children, and every operand (a to h) is a leaf. Check: the inorder traversal gives back the expression, and the postorder gives a b c - + d e - f g + h - / *.
Log in or create a free account to answer this question.