date: 2024-02-28
title: B+Tree
author:
- AllenYGY
status: DONE
tags:
- NOTE
- DataStructure
- BTree
- Algorithm
created: 2024-01-16
updated: 2024-05-31T00:58
publish: True
Binary search tree has one key to decide which of the two branches to take
M-ary search tree needs M-1 keys to decide which branch to take
M-ary search tree should be balanced in some way.
Thus, require that each node is at least half full!
A
The data items are stored in leaves
The root is either a leaf or has between two and M children
The non-leaf nodes store up to M-1 keys to guide the searching; key i represents the smallest key in subtree i+1
All non-leaf nodes (except the root) have between
All leaves are at the same depth and have between
Keys in internal Nodes
key i in an internal node is the smallest key in its i+1 subtree (i.e. right subtree of key i)
Insert Into Leaf
Insert Into Internal Node When leaf is Full and Internal Node is also Full
To insert a key K into a full internal node x:
Situation I:
Situation II:
After deleting from node x, we can access y directly and replace target by the new smallest key in x
Let u be the leaf that has
Let v be a sibling of u with at least
Let k be the key in the parent of u and v that separates the pointers to u and v
There are two cases
Case 1: v contains
Move the leftmost record from v to u
v contains
Move the rightmost record from v to u
Then set the key in parent of u that separates u and v to be the new smallest key in u