What are the differences between B trees and B+ trees?

后端 未结 14 2808
孤城傲影
孤城傲影 2020-12-02 03:18

In a b-tree you can store both keys and data in the internal and leaf nodes, but in a b+ tree you have to store the data in the

相关标签:
14条回答
  • 2020-12-02 03:53

    The primary distinction between B-tree and B+tree is that B-tree eliminates the redundant storage of search key values.Since search keys are not repeated in the B-tree,we may not be able to store the index using fewer tree nodes than in corresponding B+tree index.However,since search key that appear in non-leaf nodes appear nowhere else in B-tree,we are forced to include an additional pointer field for each search key in a non-leaf node. Their are space advantages for B-tree, as repetition does not occur and can be used for large indices.

    0 讨论(0)
  • 2020-12-02 03:55

    Adegoke A, Amit

    I guess one crucial point you people are missing is difference between data and pointers as explained in this section.

    Pointer : pointer to other nodes.

    Data :- In context of database indexes, data is just another pointer to real data (row) which reside somewhere else.

    Hence in case of B tree each node has three information keys, pointers to data associated with the keys and pointer to child nodes.

    In B+ tree internal node keep keys and pointers to child node while leaf node keep keys and pointers to associated data. This allows more number of key for a given size of node. Size of node is determined mainly by block size.

    Advantage of having more key per node is explained well above so I will save my typing effort.

    0 讨论(0)
  • 2020-12-02 03:56

    Take one example - you have a table with huge data per row. That means every instance of the object is Big.

    If you use B tree here then most of the time is spent scanning the pages with data - which is of no use. In databases that is the reason of using B+ Trees to avoid scanning object data.

    B+ Trees separate keys from data.

    But if your data size is less then you can store them with key which is what B tree does.

    0 讨论(0)
  • 2020-12-02 04:02

    One possible use of B+ trees is that it is suitable for situations where the tree grows so large that it does not fit into available memory. Thus, you'd generally expect to be doing multiple I/O's.
    It does often happen that a B+ tree is used even when it in fact fits into memory, and then your cache manager might keep it there permanently. But this is a special case, not the general one, and caching policy is a separate from B+ tree maintenance as such.

    Also, in a B+ tree, the leaf pages are linked together in a linked list (or doubly-linked list), which optimizes traversals (for range searches, sorting, etc.). So the number of pointers is a function of the specific algorithm that is used.

    0 讨论(0)
  • 2020-12-02 04:05

    B+ Trees are especially good in block-based storage (eg: hard disk). with this in mind, you get several advantages, for example (from the top of my head):

    • high fanout / low depth: that means you have to get less blocks to get to the data. with data intermingled with the pointers, each read gets less pointers, so you need more seeks to get to the data

    • simple and consistent block storage: an inner node has N pointers, nothing else, a leaf node has data, nothing else. that makes it easy to parse, debug and even reconstruct.

    • high key density means the top nodes are almost certainly on cache, in many cases all inner nodes get quickly cached, so only the data access has to go to disk.

    0 讨论(0)
  • 2020-12-02 04:06

    B+Trees are much easier and higher performing to do a full scan, as in look at every piece of data that the tree indexes, since the terminal nodes form a linked list. To do a full scan with a B-Tree you need to do a full tree traversal to find all the data.

    B-Trees on the other hand can be faster when you do a seek (looking for a specific piece of data by key) especially when the tree resides in RAM or other non-block storage. Since you can elevate commonly used nodes in the tree there are less comparisons required to get to the data.

    0 讨论(0)
提交回复
热议问题