Reproduced in: http://blog.csdn.net/tidelu77/article/details/3970075
Binary Tree obtained from the traversal Sequence
The binary tree is obtained from the pre-order traversal sequence and the middle-order traversal sequence:
For example, a binary tree has seven nodes (including the root node)
1. Create a 7*8 table and write the ordinal traversal sequence in the top row.
2. Then, the node is written in 2-8 rows in the order of the forward traversal sequence (the node and the central sequence are in the same column ).
3. Connect a node from top to bottom to the highest left node and the highest right node under the node.
The binary tree is obtained.
Example:
Pre-order traversal sequence: abdecfg
Sequential traversal sequence: dbeafcg
D |
B |
E |
A |
F |
C |
G |
|
|
|
A |
|
|
|
|
B |
|
|
|
|
|
D |
|
|
|
|
|
|
|
|
E |
|
|
|
|
|
|
|
|
|
C |
|
|
|
|
|
F |
|
|
|
|
|
|
|
|
G |
The binary tree is obtained from the post-order traversal sequence and the middle-order traversal sequence:
1 is the same as (forward and middle.
2. traverse the sequence in the descending order and fill in the table in the forward order.
3 is the same as (forward and middle 3 ).
A binary tree is a full binary tree. The binary tree is obtained from the pre-order traversal sequence and the post-order traversal sequence:
For example, a binary tree has seven nodes (including the root node)
1. Create a 7*8 table and write the post-order traversal sequence (pre-order traversal sequence) in the top row.
2. Enter the pre-order traversal sequence (post-order traversal sequence) in the order from the front to the back (from the back to the Front. Note: The newly added node cannot be on the lower left diagonal (lower right diagonal) of any added node; otherwise, an empty column is added.
3. Rotate the table clockwise for 45 °.
4 ).
Obtain the binary tree.
Example:
Pre-order traversal sequence: abdecfg
Post-order traversal sequence: debfgca
D |
E |
B |
F |
G |
C |
A |
|
|
|
|
|
|
A |
|
|
B |
|
|
|
|
D |
|
|
|
|
|
|
|
E |
|
|
|
|
|
|
|
|
|
|
C |
|
|
|
|
F |
|
|
|
|
|
|
|
G |
|
|