b tree和b+tree_B TREE实施

b tree和b+tree

B TREE及其操作简介 (Introduction to B TREE and its operations)

A B tree is designed to store sorted data and allows search, insertion and deletion operation to be performed in logarithmic time. As In multiway search tree, there are so many nodes which have left subtree but no right subtree. Similarly, they have right subtree but no left subtree. As is known, access time in the tree is totally dependent on the level of the tree. So our aim is to minimize the access time which can be through balance tree only.

B树设计用于存储排序的数据,并允许在对数时间内执行搜索,插入和删除操作。 就像在多路搜索树中一样,有许多节点具有左子树但没有右子树。 同样,它们具有右子树,但没有左子树。 众所周知,树中的访问时间完全取决于树的级别。 因此,我们的目标是最大程度地减少只能通过平衡树访问的时间。

For balancing the tree each node should contain n/2 keys. So the B tree of order n can be defined as:

为了平衡树,每个节点应包含n / 2个键。 因此,n阶的B树可以定义为:

  1. All leaf nodes should be at same level.

    所有叶节点应处于同一级别。

  2. All leaf nodes can contain maximum n-1 keys.

    所有叶节点最多可以包含n-1个密钥。

  3. The root has at least two children.

    根至少有两个孩子。

  4. The maximum number of children should be n and each node can contain k keys. Where, k<=n-1.

    子代的最大数量应为n,每个节点可以包含k个键。 其中,k <= n-1。

  5. Each node has at least n/2 and maximum n nonempty children.

    每个节点至少具有n / 2个,最多n个非空子代。

  6. Keys in the non-leaf node will divide the left and right sub-tree where the value of left subtree keys will be less and value of right subtree keys will be more than that particular key.

    非叶节点中的键将划分左右子树,其中左子树键的值将小于该左子树,而右子树键的值将大于该特定键。

Let us take a B-tree of order 5,

让我们以5阶的B树为例

Example of B tree 1

Here, we can see all leaf nodes are at same level. All non-leaf nodes have no empty sub-tree and they have keys 1 less than the number of their children.

在这里,我们可以看到所有叶节点处于同一级别。 所有非叶节点都没有空的子树,并且它们的键数比其子节点数少1。

B树上执行的操作 (Operations performed on B Tree)

  1. Insertion in B-Tree

    插入B树

  2. Deletion from B-Tree

    从B树删除

1)插入B树 (1) Insertion in B-Tree)

The insertion of a key in a B tree requires the first traversal in B-tree. Through the traversal, it is easy to find that key which needs to be inserted is already existed or not. There are basically two cases for inserting the key that are:

在B树中插入密钥需要在B树中进行第一次遍历。 通过遍历,很容易发现需要插入的密钥已经存在或不存在。 基本上有两种插入密钥的情况:

  1. Node is not full

    节点未满

  2. Node is already full

    节点已满

If the leaf node in which the key is to be inserted is not full, then the insertion is done in the node.

如果要插入密钥的叶节点未满,则在该节点中完成插入。

If the node were to be full then insert the key in order into existing set of keys in the node, split the node at its median into two nodes at the same level, pushing the median element up by one level.

如果节点已满,则按顺序将密钥插入节点中现有的密钥集中,将节点的中值拆分为同一级别的两个节点,将中值元素向上推一个级别。

Let us take a list of keys and create a B-Tree: 5,9,3,7,1,2,8,6,0,4

让我们获取一个键列表并创建一个B树:5,9,3,7,1,2,8,6,0,4

1) Insert 5

1)插入5

Insert in Binary tree 1

2) Insert 9: B-tree insert simply calls B tree insert non-full, putting 9 to the right of 5.

2)插入9 :B树插入简单地调用B树插入不完整,将9放在5的右边。

Insert in Binary tree 2

3) Insert 3: Again B-tree insert non-full is called

3)插入3 :再次调用非完整的B树插入

Insert in Binary tree 3

4) Insert 7: Tree is full. We allocate a new empty node, make it the root, split a former root, and then pull 5 into a new root.

4)插入7 :树已满。 我们分配一个新的空节点,将其设为根,拆分先前的根,然后将5拉入新的根。

Insert in Binary tree 4

5) Insert 1: It goes with 3

5)插入1 :与3对应

Insert in Binary tree 5

6) Insert 2: It goes with 3

6)插入2 :与3对应

Insert in Binary tree 6

7) Insert 8, 6: As firstly 8 goes with the 9 and then 6 would go with 7, 8, 9 but that node is full. So we split it bring its middle child into the root.

7)插入8、6 :首先8与9并存,然后6与7、8、9并存,但该节点已满。 因此,我们将其拆分为中间孩子。

Insert in Binary tree 7

8) Insert 0, 4: 0 would go with the 1, 2, and 3 which are full, so we split it sending the middle child up to the root. Now it would be nice to just stick 4 in with 3, but the B-tree algorithm requires us to split the full root. Now we can insert 4 assured that future insertion will work.

8)插入0、4 :0将与1、2和3充满,因此我们将其拆分,将中间子级发送到根。 现在将4和3坚持下去会很好,但是B树算法要求我们拆分完整的根。 现在我们可以插入4,确保将来的插入将起作用。

Insert in Binary tree 8

2)从B树删除 (2) Deletion from B Tree)

Deletion of the key also requires the first traversal in B tree, after reaching on a particular node two cases may be occurred that are:

删除密钥还需要在B树中进行第一次遍历,到达特定节点后可能会发生两种情况:

  1. Node is leaf node

    节点是叶节点

  2. Node is non leaf node

    节点是非叶节点

Example: Let us take a B tree of order 5

示例:让我们采用5阶B树

Deletion in B Tree 1

1) Delete 190: Here 190 is in leaf node, so delete it from only leaf node.

1)删除190 :此处的190位于叶节点中,因此仅从叶节点中将其删除。

Deletion in B Tree 2

2) Delete 60: Here 60 is in non leaf node. So first it will be deleted from the node and then the element of the right child will come in that node.

2)删除60 :这里60在非叶节点中。 因此,首先将其从节点中删除,然后右子元素将进入该节点。

Deletion in B Tree 3

B树的应用 (Applications of B Tree)

The main application of a B tree is the organization of a huge collection of a data into a file structure. In this insertion, deletion and modification can be carried out perfectly and efficiently.

B树的主要应用是将庞大的数据集合组织到文件结构中。 通过这种插入,可以完美而有效地进行删除和修饰。

B tree application

Full, so we split it sending the middle child up to the root. Now it would be nice to just stick 4 in with 3, but the B-tree algorithm requires us to split the full root. Now we can insert 4 assured that future insertion will work.

已满,因此我们将其拆分,将中间孩子发送到根。 现在将4和3坚持下去会很好,但是B树算法要求我们拆分完整的根。 现在我们可以插入4,确保将来的插入将起作用。

翻译自: https://www.includehelp.com/data-structure-tutorial/introduction-to-b-tree.aspx

b tree和b+tree

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/378829.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

黑色背景下,将照片内封闭空心图案的空心区域染成Cyan并保存

在黑色背景下&#xff0c;将照片内封闭空心图案的空心区域染色 import cv2 import numpy as np img cv2.imread(E:\Python-workspace\OpenCV\OpenCV/beyond.png,1)#第一个参数为选择照片的路径&#xff0c;注意照片路径最后一个为正斜杠其他都为反斜杠&#xff1b;第二个参数…

Ubuntu输入su提示认证失败的解决方法

Ubuntu输入su提示认证失败的解决方法 启动ubuntu服务时竟然提示权限不够&#xff0c;用su切换&#xff0c;输入密码提示认证失败&#xff0c;这下搞了吧&#xff0c;后来一经查阅原来Ubuntu安装后&#xff0c;root用户默认是被锁定了的&#xff0c;不允许登录&#xff0c;也不允…

SDP协议基本分析(RTSP、WebRTC使用)

目录一、介绍二、标准 SDP 规范1. SDP 的格式2. SDP 的结构&#xff08;1&#xff09;会话描述&#xff08;2&#xff09;媒体描述三、WebRTC 中的 SDP一、介绍 SDP&#xff08;Session Description Protocal&#xff09;以文本描述各端&#xff08;PC 端、Mac 端、Android 端…

MFC六大关键技术(第四部分)——永久保存(串行化)

MFC 六大关键技术 ( 第四部分 ) ——永久保存&#xff08;串行化&#xff09; 先用一句话来说明永久保存的重要&#xff1a;弄懂它以后&#xff0c;你就越来越像个程序员了&#xff01; 如果我们的程序不需要永久保存&#xff0c;那几乎可以肯定是一个小玩儿。那怕我们的记事本…

在网络中配置思科交换机

By default, all ports of a switch are enabled. As we are talking about layer 2 switching, there is no need to configure IP address or any routing protocol on the switch. In such a situation, the configuration is not focused on the switch. 缺省情况下&#…

黑色背景下,描绘照片的轮廓形状并保存

描绘照片的轮廓形状并保存 import cv2 from matplotlib import pyplot as plt # 1.先找到轮廓 img cv2.imread(E:\Python-workspace\OpenCV\OpenCV/beyond.png, 0) _, thresh cv2.threshold(img, 0, 255, cv2.THRESH_BINARY cv2.THRESH_OTSU) image, conturs, hierarchy c…

java pdf合并_Java 合并、拆分PDF文档

本文将介绍如何在Java程序中合并及拆分PDF文档&#xff0c;合并文档时&#xff0c;包括合并多个不同PDF文档为一个文档&#xff0c;以及合并PDF文档的不同页面为一页&#xff1b;拆分文档是&#xff0c;包括将PDF文档按每一页拆分&#xff0c;以及按指定页数范围来拆分。下面将…

HDU4405 期望

对于期望&#xff0c;首先&#xff0c;对于这个公式中p表示概率&#xff0c;x表示随机变量 展开则为 ex p1*x1p2*x2p3*x3....... 对于本题 假设 ex[ i ]表示当前 i 走到 n 的期望值。所以若 i 处没有飞机&#xff0c;ex[ i ]sigma(1/6*ex[ik])1 其中(k1...6) &#xff08;1表示…

调用本地电脑摄像头并进行按P进行捕获照片并保存,按下Q退出

调用本地电脑摄像头并进行按P进行捕获照片并保存&#xff0c;按下Q退出 灰度摄像头显示&#xff1a; import cv2 cap cv2.VideoCapture(0) if not cap.isOpened():print("Cannot open camera")exit() while True:# 逐帧捕获ret, frame cap.read()# 如果正确读取帧…

intersect函数_PHP array_intersect()函数与示例

intersect函数PHP array_intersect()函数 (PHP array_intersect() Function ) array_intersect() function is used to find the matched elements from two or more elements. Function “array_intersect()” compares the values of the first array with the other arrays …

很全的SQL注入语句

1、返回的是连接的数据库名and db_name()>02、作用是获取连接用户名and user>03、将数据库备份到Web目录下面;backup database 数据库名 to diskc:\inetpub\wwwroot\1.db;--4、显示SQL系统版本and 1(select VERSION) 或and 1convert(int,version)--5、判断xp_cmdshell扩展…

使用DataTable更新数据库

1、修改数据 DataRow dr hRDataSet.Tables["emp"].Rows.Find(textBox3.Text);//DataRow dr hRDataSet.Tables["emp"].Select("id"textBox3.Text)[0];dr.BeginEdit();dr["name"] textBox1.Text;dr.EndEdit();SqlCommandBuilder cmdn…

java异常体系_JAVA异常体系结构详解

一、什么是异常异常&#xff1a;程序在运行过程中发生由于硬件设备问题、软件设计错误等导致的程序异常事件。(在Java等面向对象的编程语言中)异常本身是一个对象&#xff0c;产生异常就是产生了一个异常对象。 ——百度百科二、异常体系Java把异常当作对象来处理&#xf…

对照片质量进行压缩

对照片质量进行压缩 其实无论是jpg还是png都是已经压缩编码化的格式罢了&#xff0c;原图片的大小要远远大于压缩编码后的格式 1&#xff0c;像素&#xff1a;图片放大到一定程度之后的一个个的小方块 2&#xff0c;RGB&#xff1a;每一个像素&#xff08;小方块&#xff09;都…

Silverlight访问 Apache服务器(Tomcat,Geronimo)中部署的Webservice

Silverlight 访问 Apache服务器中的Webservice 开发环境 Vs2010 、 Silverlight4 、 Java Jdk1.6 U 21 、 Apache-tomcat-6.0.20 、 Myeclipse8.5 、 Apache-ant-1.8.1 、 Axis2 、 Geronimo-tomcat6-javaee5-2.2. 下载地址&#xff1a; Apache-tomcat &#xff1a; http://apa…

那些帮助你成为优秀前端工程师的讲座——《性能篇》

这篇文章是前端优秀讲座和讨论列表系列连载第七篇&#xff0c;介绍前端性能优化技巧。前端领域发展迅速&#xff0c;只有时刻掌握前端发展趋势和技术动态&#xff0c;学习前沿的开发思想和理念才能让自己跟上时代的步伐&#xff0c;保持自己的技术优势。 您可能感兴趣的相关文章…

mca终端_MCA的完整形式是什么?

mca终端1)MCA&#xff1a;计算机应用硕士 (1) MCA: Master of Computer Application) MCA is an abbreviation of Master of Computer Application. It is a masters degree program for post-graduation in Computer applications. This post-graduate course duration is abo…

钢铁侠java_现代版“钢铁侠”,无所不能的程序员,java工程师实现人造器官!...

一位名叫利亚姆泽贝迪(Liam Zebedee)的软件工程师已经厌倦了糖尿病患者的生活挑战&#xff0c;因此他决定入侵他的胰岛素泵&#xff0c;并将其转变成一种崭新的高科技胰腺胰腺。Zebedee详细介绍了查找和订购零件的过程&#xff0c;为智能胰岛素泵编写软件的代码以及在其博客中组…

Windows下的Memcache安装 (转)

Windows下的Memcache安装&#xff1a;1. 下载memcache的windows稳定版&#xff0c;解压放某个盘下面&#xff0c;比如在c:\memcached2. 在终端&#xff08;也即cmd命令界面&#xff09;下输入 ‘c:\memcached\memcached.exe -d install’ 安装3. 再输入&#xff1a; ‘c:\memca…

C#中实现js中的eval函数功能

在js中有eval函数&#xff0c;比如 eval&#xff08;‘33*4’&#xff09;结果为15&#xff1b; 但C#中想要完成这样的功能&#xff0c;却没有相应的函数&#xff0c;可以用sql语句的方式实现&#xff0c;比如&#xff0c;执行 select 33*4 的方式。 可以先构造公式 Formula …