Question: Draw the expression tree for the expression: a b * (b c)/(d + e) + f ** g. Give the preorder and post-order traversal of
Draw the expression tree for the expression: a b * (b c)/(d + e) + f ** g. Give the preorder and post-order traversal of the expression tree so obtained. Preorder and postorder traversals are recursively defined as follows:
Preorder Traversal
1.Visit the root
2. Visit left sub-tree in preorder traversal
3. Visit right sub-tree in preorder traversal
Post-Order Traversal
1. Visit left sub-tree in post-order traversal
2. Visit right sub-tree in post-order traversal
3. Visit the root
Notes:
(1) visit a node means writing the value inside the node.
(2) The operators have the following priorities of evaluation (highest to lowest)
(i) ( )
(ii) ** (exponentiation)
(iii) /, *
(iv) +, -
(3) Operations at the same level are evaluated from left to right, except exponentiation, which are evaluated from right to left.
For example, a b + c is (a b) + c and not a (b + c). a ** b ** c = a ** (b ** c) and not (a ** b) ** c.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
