Binary search tree (understand)

   Binary search tree (Binary Search Tree), (Also: a binary search tree, binary sort tree) which is either an empty tree, or having the following properties of a binary tree : If it's left subtree is not empty, then left values of all the sub-tree nodes are less than the value of the root node; if its right subtree is not empty, then the right sub-tree, all the nodes which are greater than the value of the root; its left , they were also right subtree binary sort tree .

 

 Binary tree traversal there are three:

(1) first (root) preorder (about root)

(2) (root) preorder (left root right)

(3) (root) preorder (about root)

example :

 

 



First (root) preorder traversal (about root): ABDHEICFJKG

in (root) preorder traversal (left and right root): DHBEIAJFKCG

after (root) preorder traversal (about root): HDIEBJKFGCA

    later (root) order traversal, for example, every time first traversal of the tree left subtree, then the right subtree traverse the tree, and finally traverse the root, and so on until a complete traversal of the tree.

    In addition, there is a proposition: given any kind of binary tree traversal sequence, it can not be uniquely determined corresponding binary tree. However, in order to know if the binary tree traversal sequence and any other sequence traversal, binary tree can be uniquely determined.

Example 1: The known binary sequence postorder dabec, sequence preorder debac, its sequence preorder traversal (cedba).

(1) preorder: debac

postorder: dabec

postorder traversal of the last sequence of a node is the root node, the root node c is found.

Root node traversal sequence in the middle of the sequence, its left subtree is the left, the right is a right subtree. Therefore, from the sequence preorder can be seen, only the left sub-tree root node c, there is no right subtree.

 

(2) preorder: deba

postorder: dabe

after the last sequence preorder traversal of the node is the root, it is understood e c root left subtree.

Root node traversal sequence in the middle of the sequence, its left subtree is the left, the right is a right subtree. Therefore, from the sequence preorder can be seen, the root of the left child node e is d, a right subtree is the ba.

 

(3) preorder: ba

postorder: ab

a postorder traversal of the sequence b e understood root right subtree. Central sequence preorder can be seen, a is the right child of the root node b.

Tree as follows:

 

Reprinted from: https://blog.csdn.net/qq_34840129/article/details/80619761

 

More follow-up to be completed: https://www.cnblogs.com/mcomco/p/10184033.html

Guess you like

Origin www.cnblogs.com/-citywall123/p/11456991.html