当前位置:网站首页>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
边栏推荐
- Synergetic process
- 【OpenCV 例程 300篇】239. Harris 角点检测之精确定位(cornerSubPix)
- ECCV 2022 | 登顶SemanticKITTI!基于二维先验辅助的激光雷达点云语义分割
- [operation and maintenance, implementation of high-quality products] interview skills for technical positions with a monthly salary of 10k+
- What does the software testing process include? What are the test methods?
- 【运维、实施精品】月薪10k+的技术岗位面试技巧
- 【AI4Code】《Contrastive Code Representation Learning》 (EMNLP 2021)
- MLX90640 红外热成像仪测温传感器模块开发笔记(五)
- More accurate and efficient segmentation of organs-at-risk in radiotherapy with Convolutional Neural
- Use of Spirng @conditional conditional conditional annotation
猜你喜欢

Make a general cascade dictionary selection control based on jeecg -dictcascadeuniversal
软件测试流程包括哪些内容?测试方法有哪些?

Cmake learning notes (II) generation and use of Library

More accurate and efficient segmentation of organs-at-risk in radiotherapy with Convolutional Neural
Software testing interview question: Please list the testing methods of several items?

Interviewer: "classmate, have you ever done a real landing project?"

Alibaba cloud technology expert Qin long: reliability assurance is a must - how to carry out chaos engineering on the cloud?

卷积核越大性能越强?一文解读RepLKNet模型

If you want to do a good job in software testing, you can first understand ast, SCA and penetration testing

什么是CI/CD?
随机推荐
CONDA common commands: install, update, create, activate, close, view, uninstall, delete, clean, rename, change source, problem
Use of Spirng @conditional conditional conditional annotation
flinkcdc可以一起导mongodb数据库中的多张表吗?
MySQL implements inserting data from one table into another table
Table partition of MySQL
使用vsftpd服务传输文件(匿名用户认证、本地用户认证、虚拟用户认证)
Cmake learning notes (II) generation and use of Library
2022.07.24(LC_6125_相等行列对)
Mysql 远程连接权限错误1045问题
微软提出CodeT:代码生成新SOTA,20个点的性能提升
485 communication (detailed explanation)
2022.07.24(LC_6124_第一个出现两次的字母)
"Autobiography of Franklin" cultivation
Implementation of recommendation system collaborative filtering in spark
Kyligence was selected into Gartner 2022 data management technology maturity curve report
word样式和多级列表设置技巧(二)
Deployment of Apache website services and implementation of access control
2022 年中回顾 | 大模型技术最新进展 澜舟科技
艰辛的旅程
I want to ask whether DMS has the function of regularly backing up a database?