Binary sort tree (b-tree) and balance tree (AVL tree)

Source: Internet
Author: User

Binary sort tree, also known as B-Tree, is a data structure commonly mentioned in the search algorithm, this paper introduces its basic concept and search process, analyzes its search efficiency, and then leads to the concept of balance tree (AVL tree). structure of the B-tree

The B-tree is either a two-fork search tree or a two-fork sort tree (binary sorttrees), or a two-fork lookup tree .

It is either an empty tree or a two-fork tree with the following properties:

1. If its left subtree is not empty, then the value of all nodes on the left subtree is less than the value of its root node;

2. If its right subtree is not empty, then the value of all nodes on the right subtree is greater than the value of its root node;

3. Its left and right sub-trees are also two-fork sorting trees respectively.

in order to get an ordered sequence, the middle sequence traverses the binary sort tree. find on binary sort tree

First, the given value and the root node of the keyword comparison, if equal, the search succeeds, if not equal, based on the given value and the root node key between the size of the relationship between the left subtree or the right subtree to continue to find.

If an empty tree is found, it indicates that there are no unknown origin records in the tree, so the lookup is unsuccessful. Search Analysis of two-fork sorting tree

The process of finding nodes whose keywords are equal to a given value on a binary sort tree, just a path from the root node to the node, the number of keywords compared to the given value equals the path length plus 1 (or the number of nodes in the hierarchy), so, like binary lookup, the number of keywords compared to the given value does not exceed the depth of the tree.

However, binary finds the decision tree of a table of length n is unique, while a two-fork sort tree with n nodes is not unique.

The average search length of the two-fork sorting tree with n nodes is related to the tree morphology, and the two-fork sort tree is transformed into a single tree when the keywords are inserted sequentially.

At this point the depth of the tree is n, its average lookup length is (n+1)/2, and the order lookup is the same, which is the worst case.

Obviously, the best case should be that the shape of the two-fork sort tree is the same as the decision tree for the binary lookup, whose average lookup length is proportional to the log2n, i.e. we want the binary sort tree to be balanced . balanced two-pronged tree

Balanced binary trees (Balanced binary tree or height-balanced tree) are also known as AVL trees .

It is either an empty tree or a two-fork tree with the following properties:

Its Saozi right subtree is a balanced binary tree, and the absolute value of the depth difference of the Saozi right subtree is not more than 1.

If the balance factor bf (Balance Factor) of the node on the two-fork tree is defined as the left subtree depth of the node minus the depth of its right subtree, then the equilibrium factor of all nodes on the balanced binary tree may be -1,0 and 1.

The time complexity for finding on the balance tree is O (logn).

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.