B-Tree | B+Tree |
---|---|
All internal nodes and leaf nodes contain data pointers along with keys. | Only leaf nodes contain data pointers along with keys, internal nodes contain keys only. |
There are no duplicate keys. | Duplicate keys are present in this, all internal nodes are also present at leaves. |
Leaf nodes are not linked to each other. | Leaf nodes are linked to each other. |
Sequential access of nodes is not possible. | All nodes are present at leaves, so sequential access is possible just like a linked list. |
Searching for a key is slower. | Searching is faster. |
For a particular number of entries, the height of the B-tree is larger. | The height of the B+ tree is lesser than B-tree for the same number of entries. |
其实这几点区别都是根据 B-Tree 和 B+tree 的结构总结出来的。
与上图中的 B+Tree 结构不同,B-Tree 每个节点中都存储者数据指针和 key,从上之下没有重复的 key,页节点之间也没有链接。
- B-Tree 中查找数据,需要遍历完第一个分支后回到根节点继续遍历第二个分支,以此类推查找。B+Tree 中除了页节点以外的节点只存储 key 值,一个 page 可以存储更多的 key,减少了树的高度,且 B+Tree 的叶节点间具有双向指针,呈双向链表的结构,查找起来更加迅速。
- B-Tree 呈树状,每个节点 key 都不重复,因此不存在顺序结构。B+tree 中所有数据都存在叶节点,按照 key 顺序排列,可以按照顺序访问。