Two-point search decision Tree

Source: Internet
Author: User

5, two-point search decision tree
The binary search process can be described using a two-fork tree: The nodes in the middle of the current search interval as the root, and the nodes in the Zoozi and right child tables as the Saozi right subtree of the root. The resulting two-fork tree, called the decision Tree (decision tree) or the comparison tree, that describes the binary lookup (Comparison tree).
Note:
The shape of the decision tree is related only to the number of table nodes n, but not to the value of R[1..n].keys in the input instance.
An ordered table with 11 nodes can be represented by the decision tree shown.



(1) The composition of two-point search decision tree
① The Circle node is the inner node in the tree. The number within the Circle node in the tree represents the position of the node in the ordered table.
② external nodes: all null pointers in a round node are replaced by a virtual square node, which is an external node.
The marks "<", "(", ">", ")" on the Left (right) branch of a node I and its left (right) child in the ③ tree indicate: When unknown origin keyword K<r[i].key (k>r[i].key), the left (right) branch should go to the left (right) child of I, Compare the child's keywords further to the K. If it is equal, the lookup process ends with a return, otherwise the k is compared to the next-level node in the tree.

(2) Finding a decision tree with two points
Binary lookup is the comparison between the given value K and the root node of the two-point lookup decision tree. If equal, success. Otherwise, Jochiugen the keyword of the node to find in the left subtree. Jordahugen the keyword of the node, find it in the right subtree.
"Example" for a table with 11 nodes, if the found node is the 6th node in the table, then only one comparison is needed, and if the found node is the 3rd or 9th node in the table, two comparisons are required, and the first 1,4,7,10 node needs to be compared three times, and the first 2,5,8,11 node needs to be compared four times.
Thus, the successful binary search process happens to be a path from the root of the decision tree to the node being looked at, and the number of times the keyword has been compared is exactly the level of the node in the tree. If the lookup fails, the comparison process is through a path from the decision tree root to an external node, and the number of keyword comparisons required is the sum of the internal nodes on that path.
The keyword sequence for the "example" unknown origin table is: (05,13,19,21,37,56,64,75,80,88,92), to find the records of k=85, the internal nodes passed were 6, 9, 10, and finally reached the square node "9-10", with a comparison number of 3.
In fact, the meaning of "i-i+1" in square nodes is that the lookup value K is between R[i].key and R[i+1].key, that is, R[i].key<k<r[i+1].key.

(3) Average lookup length for binary search
The total number of internal nodes is n=2h-1, and the decision tree is a full two-fork tree with a depth of H=LG (n+1) (depth h excluding external nodes). The number of nodes on the K-level in the tree is 2k-1, and the number of comparisons required to find them is K. Therefore, in the equal probability hypothesis, the average lookup length when the binary search succeeds is:
ASLBN≈LG (n+1)-1
Binary lookup The number of keywords that are required to compare when a lookup fails does not exceed the depth of the decision tree, and in the worst case, the comparison number of successful lookups does not exceed the depth of the decision tree. That is:

The worst performance and average performance of binary lookups are fairly close.

6. Advantages and disadvantages of two-point search
Although binary lookups are efficient, you want to sort the tables by keyword. The sort itself is a time-consuming operation. It also takes an O (NLGN) time to use an efficient sorting method.
Binary lookup applies only to sequential storage structures. To maintain the order of the table, it is necessary to move a large number of nodes to insert and delete in the sequential structure. As a result, binary search is especially useful for linear tables that are rarely modified and often need to be found once created.
For those linear tables that find little and often need to be changed, a chain list can be used as a storage structure for sequential lookups. Binary lookups cannot be implemented on a linked list.

Two-point lookup decision tree

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.