Example 02 - More About Algebraic Tree
In previous example we demonstrated how to build an algebraic tree for a simple addition
expression. In this chapter we will walk through building arbitrarily complicated
algebraic tree.
General Rules of Building Algebraic Tree
The following is a three step rule to build an algebraic tree.
- Write down the algebraic expression in the way we usually do
For example:
((a * b + c * d) / e + (f * g + h * i) / 2) / 12
- Use parenthesis to group the "operators" based on the precedence of evaluation
For example, for the expression above, we have:
((((a * b) + (c * d)) /
e) + (((f * g) + (h * i)) /
2))
/ 12
In order to make it clear we use color code to show different
group of parenthesis.
- Build the
expression from "outer" parenthesis groups to "deeper" parenthesis groups
The "deeper" the expression in the parenthesis grouping, the deeper tree node
it belongs to in the expression tree. Deeper tree nodes should be added later than
the "shallower" nodes.
Example 2.1: The Expression Tree of the Above Expression
The following screen shot shows the expression tree of the expression: ((a * b +
c * d) / e + (f * g + h * i) / 2) / 12
Tips: User can add comments to expression tree node by writing
text in the upper right panel. The lower panel displays the pseudo-code of the expression.
Example 2.2: Another Expression Tree Example
The follow is the tree of a Boolean expression: (a AND b) OR
(c AND d)