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.pswp.cn/news/378829.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378829.shtml
英文地址,請注明出處:http://en.pswp.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 …