B-tree Ramble (from two fork tree to two fork search tree to balance tree to red-black tree to B-tree to C + Tree to b* tree)

Source: Internet
Author: User

The study of B-tree still needs some notes.

B-trees are a balanced lookup tree designed for disk or other direct-access secondary storage devices. The difference between a B-tree and a red-black tree is that B-trees can have many children, from several to thousands of. For example, a branch factor of 1001, a height of 2 B-tree, he can store more than 1 billion keywords, however, because the root node (only one) remains in main memory, so in this book, to find a keyword more than two times the disk access.

The structure of the disk, as well as the principle of writing and reading data, is skipped here.

First, overview:

1) For each node of the B-Tree X is:

A) n[x], the number of key words currently stored in node X,

b) keywords are stored in non-descending order, so key1[x]<=key2[x]<=...<=keyn[x]

c) Leaf[x], is a Boolean value that is used to indicate that the node x is not the leaf nodes.

2) Each inner node contains n[x] + 1 pointers pointing to its children c1[x], c2[x], ..., c (n[x]+1) [x]. Of course, the leaf node does not have a C definition.

3) Keyi[x] separates the range of keywords stored in each subtree.

4) Each leaf node has the same height.

5) Each node can contain a number of key words with an upper bound and a lower bound. These realms can be represented by a fixed integer T >=2, called the minimum degree of a B-tree.

Theorem: H <= log T Bottom (n+1)/2. Proof slightly. See Introduction to Algorithms.

Second, the basic operation:

The B-tree is similar to searching for binary search trees, where each node does not have a "two-way selection" but a "multiple-way selection based on the number of children".

1) Create an empty B-tree:

First, create an empty root node, and then insert the new keyword by inserting it. Last Disk-write Write

2) Insert:

Inserting a new node into the tree is, of course, without violating the validity of the B-tree. So if the node y that the new node is going to insert is a full leaf node,

It is necessary to introduce a "split" operation to divide the node from the Middle keyword keyt[y] into two nodes with t-1 keywords. The middle keyword is promoted

To the parent node of Y. Of course, if the parent node of Y is also full, then ensure that both parents are dissatisfied with the split operation before y does the split operation.

In order to meet the above requirements: when we find the ownership of the current new node from top to bottom, we will split the full node along the way, then we can guarantee that whenever we want to split a

Full node y, make sure its parents are not full. It can be seen that the only way the tree grows tall is to split the root node.

First, create a new node Z and then the original y node of t ... 2t-1 (t-1) to the new node Z, and then put the middle keyword in y

The parent node.

Insert the keyword into the B-tree using one-way downlink traversal tree:

It's straight. From the introduction of algorithms

  

A picture wins thousands of words.

4) Delete operation

For node x recursive invocation of B-tree-delete, the number of keywords for x is at least equal to the minimum t. Attention! This requirement is higher than the previous requirement (the minimum level in the B-tree

Number of keys t-1) One more, so that sometimes a keyword must be transferred to a child node before the recursion drops to a child node of a node. The condition of this strengthening

Allows us to delete a keyword from the tree during a trip down.

   

The delete operation is a little more complicated. Summarize the complexity: for a B-tree with a height of H, it requires only O (h) disk access operations. The required CPU time is o (th) = O (tlogt N).

B-tree Ramble (from two fork tree to two fork search tree to balance tree to red-black tree to B-tree to C + Tree to b* tree)

Related Article

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.