Java Reference
In-Depth Information
This is post-order traversal :
1.
Traverse the left subtree in post-order.
2.
Traverse the right subtree in post-order.
3.
Visit the root.
Here we traverse the left and right subtrees before visiting the root.
The post-order traversal of this tree
A
C
B
is B C A .
The post-order traversal of this tree
C
E
G
N
B
A
F
K
J
H
is H F B E A J K N G C .
Note that the traversals derive their names from the place where we visit the root relative to the traversal of
the left and right subtrees. As another example, consider a binary tree that can represent the following arithmetic
expression:
(54 + 37) / (72 - 5 * 13)
Here is the tree:
/
+
-
54
37
72
*
5
13
The leaves of the tree contain the operands, and the branch nodes contain the operators. Given a node
containing an operator, the left subtree represents the first operand, and the right subtree represents the second
operand.
The pre-order traversal is: / + 54 37 - 72 * 5 13
The in-order traversal is: 54 + 37 / 72 - 5 * 13
The post-order traversal is: 54 37 + 72 5 13 * - /
 
Search WWH ::




Custom Search