当前位置:网站首页>B tree and b+ tree
B tree and b+ tree
2022-07-25 12:59:00 【51CTO】
B Trees

B A tree is a multi-path balanced lookup tree . Key value pairs stored in each node , Index and data .m rank B The definition of a tree :
Each node has at most m Child node , At most m-1 Key words , At least m/2 Key words .( The root node can have at least one element )
The keywords in each node are sorted from small to large , All keywords in the left subtree of each keyword are smaller than it , All keywords in the right subtree are larger than it .
All leaf nodes are on the same layer .
B Tree insertion :
When a keyword is inserted into a node , If the number of keywords in the node is less than or equal to m-1, Insert complete , Otherwise, put the keyword in the middle of the node into the parent node , The left and right parts are split into the left and right subtrees of the parent node .
Example : stay 5 rank B In the tree , Nodes have at most 4 Key words , There are at least two keywords :

Insert 23,25,39:

At this time, the keyword of the left subtree has been greater than 4 A the , It needs to be split :

B Tree delete :
In the first place to find B Elements to be removed from the tree , If the element is in B There is... In the tree , Then delete the element in its node ; After deleting this element , First, judge whether the element has left and right child nodes , If there is , Move up a similar element in the child's node (“ Left child's rightmost node ” or “ The leftmost node of the right child ”) Go to the parent node , And then the situation after the move ; without , Delete directly .
Delete the element in the leaf node :
- After deletion, the number of elements in the node is less than m/2, We need to see whether a neighboring brother node is full ;
- If it's full , Then borrow an element from the parent node , Then the first or last element of the adjacent node moves up to the parent node ;
- If none of their neighbors is full , That is, the number of nodes is equal to m/2, Then the node and its adjacent sibling node “ Merge ” Become a node ;





B+ Trees

m rank B+ Trees :
Each node has at most m Child node , Each subtree corresponds to a keyword , At most m Key words , At least m/2 Key words .
And B The difference between trees :
1.B+ The data of the tree is stored in the leaf node , Internal nodes do not store data , Store index only . therefore B+ The query time complexity of the tree is fixed as logn, and B The query time complexity of the tree is not fixed , And key The position in the tree is related to , Best for O(1).B+ Because the internal nodes of the tree only store indexes , Therefore, each node can index a larger range ,B+ Trees are more suitable for external storage .
2. Each leaf node has pointers to adjacent leaf nodes , All leaf nodes are linked from small to large according to the size of keywords . It is very suitable for range query .
3. The parent node has the first keyword of each child node .

B+ Tree insertion :
When the number of node elements is greater than m-1 when , Split into two parts according to the middle element , The intermediate element is split into the parent node and stored as an index , But the middle element itself is still split on the right .
Example :5 rank B+ Tree species , Minimum nodes 2 Elements , most 4 Elements . Insert 5,10,15,20:

Insert 25, At this time, the number of elements is greater than 4 A the , split :

Then insert 26,30, Continue to split :


Reference resources :
https://segmentfault.com/a/1190000020416577
https://blog.csdn.net/weixin_43156699/article/details/117216784
https://blog.csdn.net/qq_34515959/article/details/109155630
https://blog.csdn.net/a519640026/article/details/106940115
边栏推荐
- CONDA common commands: install, update, create, activate, close, view, uninstall, delete, clean, rename, change source, problem
- 2022.07.24(LC_6125_相等行列对)
- MySQL remote connection permission error 1045 problem
- 2022.07.24 (lc_6126_design food scoring system)
- Microsoft proposed CodeT: a new SOTA for code generation, with 20 points of performance improvement
- 【AI4Code】《GraphCodeBERT: Pre-Training Code Representations With DataFlow》 ICLR 2021
- Chapter5 : Deep Learning and Computational Chemistry
- 【历史上的今天】7 月 25 日:IBM 获得了第一项专利;Verizon 收购雅虎;亚马逊发布 Fire Phone
- I want to ask whether DMS has the function of regularly backing up a database?
- Perf performance debugging
猜你喜欢

Zero basic learning canoe panel (15) -- CAPL output view

【AI4Code】《Contrastive Code Representation Learning》 (EMNLP 2021)

Chapter5 : Deep Learning and Computational Chemistry
![[problem solving] org.apache.ibatis.exceptions PersistenceException: Error building SqlSession. 1-byte word of UTF-8 sequence](/img/fd/245306273e464c04f3292132fbfa2f.png)
[problem solving] org.apache.ibatis.exceptions PersistenceException: Error building SqlSession. 1-byte word of UTF-8 sequence

If you want to do a good job in software testing, you can first understand ast, SCA and penetration testing
![[300 opencv routines] 239. accurate positioning of Harris corner detection (cornersubpix)](/img/a6/c45a504722f5fd6e3c9fb8e51c6bb5.png)
[300 opencv routines] 239. accurate positioning of Harris corner detection (cornersubpix)

The programmer's father made his own AI breast feeding detector to predict that the baby is hungry and not let the crying affect his wife's sleep

“蔚来杯“2022牛客暑期多校训练营2 补题题解(G、J、K、L)

【C语言进阶】动态内存管理

【历史上的今天】7 月 25 日:IBM 获得了第一项专利;Verizon 收购雅虎;亚马逊发布 Fire Phone
随机推荐
Deployment of Apache website services and implementation of access control
MySQL remote connection permission error 1045 problem
mysql有 flush privileges 吗
Selenium uses -- XPath and analog input and analog click collaboration
Zero basic learning canoe panel (13) -- trackbar
我在源头SQLServer里面登记绝对删除的数据,传到MaxComputer,在数据清洗的时候写绝对
Go: Gin custom log output format
massCode 一款优秀的开源代码片段管理器
[机器学习] 实验笔记 – 表情识别(emotion recognition)
迁移PaloAlto HA高可用防火墙到Panorama
Zero basic learning canoe panel (12) -- progress bar
Maskgae: masked graph modeling meets graph autoencoders
AtCoder Beginner Contest 261 F // 树状数组
Microsoft proposed CodeT: a new SOTA for code generation, with 20 points of performance improvement
yum和vim须掌握的常用操作
[operation and maintenance, implementation of high-quality products] interview skills for technical positions with a monthly salary of 10k+
JS 中根据数组内元素的属性进行排序
ECCV 2022 | climb to the top semantickitti! Semantic segmentation of LIDAR point cloud based on two-dimensional prior assistance
Docker学习 - Redis集群-3主3从-扩容-缩容搭建
程序的内存布局