I'm having some trouble understanding expression trees especially with putting this expression into a tree:
S/P^Q^R
Any help with how to do these is greatly appreciated thanks
I'm having some trouble understanding expression trees especially with putting this expression into a tree:
S/P^Q^R
Any help with how to do these is greatly appreciated thanks
Copyright © 2021 JogjaFile Inc.
An expression tree is a tree that visualises the evaluation order of the expression. In your case, since you have neither given any information on operator precedence or included parentheses in the expression, there is more than one possible expression tree. If we assume that / is evaluated before ^, you would get an expression tree like
Working your way back up from the leaves to the root, you can recover the expression: $$(S/P)$$ $$(S/P)^Q$$ $$((S/P)^Q)^R$$
If we assume that ^ is evaluated before /, there are two possibilities, either $$S/((P^Q)^R) \quad \text{or}$$ $$S/(P^{(Q^R)}),$$ which would correspond to the expression trees
respectively. If you have no information with regards to operator precedence, then these three expression trees are all correct expression trees for your expression.