Three kinds of binary tree traversal-pre-order, middle-order, and post-order traversal:
Pre-order/pre-order traversal : The order of reading is: root-left-right The
order is: ABDGHCEIF
Middle-order traversal : the order of reading is: left-root-right The
order is: GDHBAEICF
Post-order traversal : the reading order is: left-right-root, the
order is: GHDBIEFCA
For known conditions:
known in-order and post-order: the last node of a post-order binary tree is the root node, and the left and right subtrees of the root of the in-order binary tree are left and right subtrees. In addition, the decomposition can be sorted , As follows,
middle order: DCEF AKJLIM
post-order: DFEC KJMIA
1. Decompose and sort the left subtree with A as the root node:
(1) "DCEF" in the middle order and "DFEC" in the subsequent order can be decomposed and sorted. Sort first, the left is the middle order, the right is the post-order
(2) and then the BHG of the middle order and the HGB of the post-order are sorted, the left is the middle order, and the right is the post-order
2. Then the right of the root node is A Sort the subtrees:
The final result is shown in the figure:
the pre-order traversal is: ABCDEFGHIJKLM.
Note: In the case of empty left subtree or right subtree, when starting contact, try to include empty nodes as much as possible, and omit the result without writing it in.