It is particularly emphasized that the decision tree of the binary lookup is a tree of balance .
Generally for an ordered sequence of binary lookup process, need to start from the middle node to compare, so it will go to the left subtree or right sub-tree to compare, so as long as the root of the tree to understand how to determine, you can recursively deal with the right and left sub-tree, that is, mid and left two halves of the element corresponding to the subtree
For example, build a decision tree for an ordered table of 12 elements.
Suppose it is 1,2,3,4, ..., 12
Then mid= (1+12) ÷2=6 mid = (1+12) \div 2 = 6, thus, the root node is 6. Split the left and right halves respectively:
Left: 1,2,3,4,5;
Right: 7, 8, 9, 10, 11, 12;
Choose a root node on the left: (1+5) ÷2=3 (1+5) \div 2 = 3
Then the left half is divided into two parts:
Left: 1, 2;
Right: 4, 5;
Special emphasis is placed on how to fix root nodes when there are only two elements, like the algorithm:
Select a root node: (1+2) ÷2=1 (1+2) \div 2 = 1
That is, choose 1 as the root node, and 2 is its right child.
The same treatment 4, 5.
The left subtree is processed and the right subtree is processed again.
A block diagram allows you to see the recursion of the subtree.
Therefore, the construction process of the binary search decision tree is traceable and more intuitive, not a blind shot of the head of the algorithm.