Expression trees are those in which the leaf nodes have the values to be operated, and internal nodes contain the operator on which the leaf node will be performed.
4 + ((7 + 9) * 2) will have an expression tree as follows
Let T be the expression tree.
If T is not NULL:
If T->data is an operand:
return T.data
A = solve(T.left)
B = solve(T.right)
--> Calculate operator for 'T.data' on A and B, and call recursively,
return calculate(A, B, T.data)
To construct an Expression Tree for the given expression, we generally use Stack Data Structure.
Initially we Iterate over the given postfix expression and follow the steps as given below -