B Tree definition B tree of order m
B+ Tree
definition B+ tree of order m 由兩個level所組成: Index level 及Data level 所組成 n 所有Data均存在於Data Blocks on Data Level, Data Blocks之間以Link list串連 n Index Block主要是依據key, 配合索引, 找到對應的Data Block n 而Index Block及Data Block中的Degree數必須符合B tree of order m的規定 B+ Tree (balanced Tree):所有樹葉到樹根的距離都相同 每個節點有 +m/2 T~ m個子女(樹根除外) 所有樹葉都在同一層(樹根到樹葉的深度皆相同) 具有n個子女非樹葉節點有n-1個鍵 n n 可以support ISAM (Index Sequential Access Method), 主要用在external search, SORT上 p 2.
Creat a B+ tree n 插入的順序為 : 9, 6, 1, 8, 4, 13, 10, 7 6 6, 9 1 6, 8 6, 9 1 6 8, 9 8 6, 8 1, 4 6 9 6 8, 9 1, 4 6 8 9, 13 p 5.
8 9 , 10 6 6 1, 4 8 9 10, 13 8 9 , 10 6 1, 4 6, 7 8 9 10, 13 p 6.
Insert a key n n Insert a key into a leaf which still has some room (not overflow). Put the keys of this leaf in order. No changes are made in the index level. insert 4 6 1 6, 9 6 1, 4 6, 9 p 7.
n n If a key is inserted into a full leaf (overflow) Split, the new leaf node is included in the sequence set, keys are distributed evenly between the old and the new leaves, and the first key from the new node is copied (not moved, as in B-tree) 6 Insert 10 6 1, 4 6, 9 1, 4 The parent is not full Insert 3 6, 9 6 9, 10 3 1 6, 9 3, 4 6 9, 10 The parent is full p 8.
Delete a key n n Delete a key from a leaf leading to no underflow Delete the leaf and keep remaining keys in order index level 可刪可不刪 6, 9 1, 4 6 delete 4 6, 9 9, 10 1 6 9, 10 delete 9 6, 10 1, 4 6 6, 9 10 1, 4 6 10 p 9.
n n Delete a key from a leaf causes an underflow Rotation or Combination 6 6 3 1 6, 9 3, 4 6 delete 1 9, 10 4 3 6, 9 4 6 9, 10 delete 6 6, 9 1 3, 4 9, 10 p 10.
EX: B+ Tree of order 3. (a) Initial tree 60 20 , 40 5, 10 20 Index level 80 40, 50 60 80, 100 Data level p 11.
(b) Insert “ 120” 60 20 , 40 5, 10 20 Overflow 80 40, 50 60 80, 100, 120 60 20 , 40 5, 10 20 80 , 100 40, 50 60 80 100, 120 p 12.
(c) Insert “ 150” 60 20 , 40 5, 10 20 Overflow 80 , 100 40, 50 60 80 100, 120, 150 60 , 100 20 , 40 5, 10 20 40, 50 80 60 120 80 100 120, 150 p 13.
(c) Delete “ 40” 60 , 100 20 , 40 5, 10 20 80 40, 50 60 120 80 100 120, 150 60 , 100 20 , 50 5, 10 20 80 50 60 120 80 100 120, 150 p 14.
(c) Delete “ 100” 60 , 100 20 , 40 5, 10 20 80 40, 50 60 120 80 100 120, 150 Under flow rotation 60 , 120 20 , 50 5, 10 20 80 50 60 150 80 120 150 p 15.
(c) Delete “ 150” 60 , 120 20 , 50 5, 10 20 80 50 60 150 80 120 150 60 20 , 50 5, 10 20 80 , 120 50 60 80 120 p 16.
- Slides: 16