420 likes | 512 Views
BTrees. B-Tree Example (Order 2). 51. 11 30. 66 78. 2 7. 12 15 22. 35 41. 53 54 63. 68 69 71 76. 79 84 93. Find Example. 51. Find record with key 22. 11 30. 66 78. 2 7. 12 15 22. 35 41. 53 54 63. 68 69 71 76. 79 84 93. Find Example. 51. Find record with key 22. 11 30.
E N D
B-Tree Example (Order 2) 51 11 30 66 78 2 7 12 15 22 35 41 53 54 63 68 69 71 76 79 84 93
Find Example 51 Find record with key 22 11 30 66 78 2 7 12 15 22 35 41 53 54 63 68 69 71 76 79 84 93
Find Example 51 Find record with key 22 11 30 66 78 2 7 12 15 22 35 41 53 54 63 68 69 71 76 79 84 93 Find locates record here
Insert Example #1 51 Insert record with key 57 11 30 66 78 2 7 12 15 22 35 41 53 54 63 68 69 71 76 79 84 93
Insert Example #1 51 Insert record with key 57 11 30 66 78 2 7 12 15 22 35 41 53 54 63 68 69 71 76 79 84 93 Find locates record here
Insert Example #1 51 Insert record with key 57 11 30 66 78 2 7 12 15 22 35 41 53 54 57 63 68 69 71 76 79 84 93 Insert record into leaf node
Insert Example #2 51 Insert record with key 72 11 30 66 78 2 7 12 15 22 35 41 53 54 57 63 68 69 71 76 79 84 93
Insert Example #2 51 Insert record with key 72 11 30 66 78 2 7 12 15 22 35 41 53 54 57 63 68 69 71 76 79 84 93 Find locates record here
Insert Example #2 51 Insert record with key 72 11 30 66 78 53 54 57 63 68 69 71 76 2 7 12 15 22 35 41 79 84 93 Create a new node
Insert Example #2 51 Insert record with key 72 11 30 66 78 53 54 57 63 68 69 71 72 76 2 7 12 15 22 35 41 79 84 93 Put record into its proper place among the records in leaf node.
Insert Example #2 51 Insert record with key 72 11 30 66 71 78 53 54 57 63 68 69 72 76 2 7 12 15 22 35 41 79 84 93 SPLIT leaf node: - 1st d records stay in node - middle record to parent node - last d records to new node
Insert Example #2 51 Insert record with key 72 11 30 66 71 78 Repeat if no room in parent node. 53 54 57 63 68 69 72 76 2 7 12 15 22 35 41 79 84 93
Insert Example #3 51 Insert record with key 55 11 30 66 71 78 53 54 57 63 68 69 72 76 2 7 12 15 22 35 41 79 84 93 Find locates record here
Insert Example #3 51 Insert record with key 55 11 30 66 71 78 53 54 57 63 68 69 2 7 12 15 22 35 41 72 76 79 84 93 Create a new node
Insert Example #3 51 Insert record with key 55 11 30 66 71 78 53 54 55 57 63 68 69 2 7 12 15 22 35 41 72 76 Put record into its proper place among the records in leaf node. 79 84 93
Insert Example #3 51 Insert record with key 55 11 30 55 66 71 78 5354 5763 68 69 2 7 12 15 22 35 41 72 76 SPLIT leaf node: - 1st d records stay in node - middle record to parent node - last d records to new node 79 84 93
Delete Example #1 51 Delete record with key 71 11 30 66 78 2 7 12 15 22 35 41 53 54 63 68 69 71 76 79 84 93
Delete Example #1 51 Delete record with key 71 11 30 66 78 2 7 12 15 22 35 41 53 54 63 68 69 71 76 79 84 93 Find locates record here
Delete Example #1 51 Delete record with key 71 11 30 66 78 2 7 12 15 22 35 41 53 54 63 68 69 76 79 84 93 Remove record from leaf
Delete Example #2 51 Delete record with key 78 11 30 66 78 2 7 12 15 22 35 41 53 54 63 68 69 76 79 84 93
Delete Example #2 51 Delete record with key 78 11 30 66 78 Find locates record here 2 7 12 15 22 35 41 53 54 63 68 69 76 79 84 93
Delete Example #2 51 Delete record with key 78 11 30 66 78 2 7 12 15 22 35 41 53 54 63 68 69 76 79 84 93 Locate next highest record (always in a leaf node).
Delete Example #2 51 Delete record with key 78 11 30 66 79 OVERWRITE delete record with leaf node record. 2 7 12 15 22 35 41 53 54 63 68 69 76 79 84 93
Delete Example #2 51 Delete record with key 78 11 30 66 79 2 7 12 15 22 35 41 53 54 63 68 69 76 79 84 93 Remove record from leaf.
Delete Example #2 51 Delete record with key 78 11 30 66 79 2 7 12 15 22 35 41 53 54 63 68 69 76 84 93
Delete Example #3 51 Delete record with key 35 11 30 66 79 2 7 12 15 22 35 41 53 54 63 68 69 76 84 93
Delete Example #3 51 Delete record with key 35 11 30 66 79 2 7 12 15 22 35 41 53 54 63 68 69 76 84 93 Find locates record here
Delete Example #3 51 Delete record with key 35 11 30 66 79 2 7 12 15 22 41 53 54 63 68 69 76 84 93 Remove record from leaf. Tree is now UNBALANCED!
Delete Example #3 51 Delete record with key 35 11 30 66 79 2 7 12 15 22 41 53 54 63 68 69 76 84 93 If neighbor has at least d+1 records, redistribute records between: neighbor, parent, and find node.
Delete Example #3 51 Delete record with key 35 11 22 66 79 2 7 12 15 30 41 53 54 63 68 69 76 84 93 Tree is now balanced.
Delete Example #4 51 Delete record with key 7 11 22 66 79 2 7 12 15 30 41 53 54 63 68 69 76 84 93
Delete Example #4 51 Delete record with key 7 11 22 66 79 2 7 12 15 30 41 53 54 63 68 69 76 84 93 Find locates record here
Delete Example #4 51 Delete record with key 7 11 22 66 79 2 12 15 30 41 53 54 63 68 69 76 84 93 Remove record from leaf. Tree is now UNBALANCED!
Delete Example #4 51 Delete record with key 7 11 22 66 79 2 12 15 30 41 53 54 63 68 69 76 84 93 Neighbors are too small (< d+1 records). Combine delete node, parent record, neighbor into single node.
Delete Example #4 51 Tree is UNBALANCED! Repeat balancing. Delete record with key 7 22 66 79 2 11 12 15 30 41 53 54 63 68 69 76 84 93
Delete Example #4 51 Neighbor has < (d+1) records. COMBINE self, parent, neighbor. Delete record with key 7 22 66 79 2 11 12 15 30 41 53 54 63 68 69 76 84 93
Delete Example #4 Children of root collapse into root node. Delete record with key 7 22 51 66 79 2 11 12 15 30 41 53 54 63 68 69 76 84 93