Constructing decision tree by sequential sequence binary lookup

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.