Database Reference
In-Depth Information
Figure A1-9b.
Detailed Post-order Traversal Algorithm
Example 4:
Figure
A1-9c
provides an example of the application of the post-order
algorithm.
Figure A1-9c.
Example of Post-order Traversal Algorithm
A1.2.7 Using Binary Tree to Evaluate Expressions
We can use binary trees to evaluate expressions by following a simple convention: All
operands are leaves of the tree and the operators are parent nodes.
Example 5:
The expression (a - b) * c is represented on a binary tree as shown in
Figure
A1-10a
. To load an expression to tree, repeatedly select the operator that divides
the expression into two, as the root. In the end leaves are operands and roots are
operators.