The relative order of the leaf nodes of any binary tree in the pre-order, middle-order, and post-order traversal sequence remains unchanged

The relative order of the leaf nodes of any binary tree in the pre-order, middle-order, and post-order traversal sequence does not change. The explanation is as follows:

Because according to the order and characteristics of the three traversals: the preorder is the left and right roots, the middle order is the left root and the right, and the postorder is the left and right roots, so the relative order changes are the roots of the subtrees, that is, the branch nodes.

For example: For a binary tree with full 3 levels, number the natural numbers divided by 0 from left to right for each level (first level, 1; second level, 2, 3; third level, 4, 5, 6, 7), then The pre-order traversal is 1245367. For the root node numbered 1, 245 is the left branch and 367 is the right branch; for 2, 4 is the left and 5 is the right; for 3, 6 is on the left, and 7 is on the right, So the first order traversal is the left and right roots. Similarly, the middle order is the left root right, and the subsequent order is the left and right roots. The first order, the middle order, and the last order are all left and then right. Insert picture description here
Reprinted: https://zhidao.baidu.com/question/536605118.html

Guess you like

Origin blog.csdn.net/jiahuiandxuehui/article/details/111825931