Comparison and Construction of B-Trees and B+ Trees
Fundamentals of B-Tree Data Structures
Definition and Node Composition: * In a B-tree structure, both keys and data can be stored within internal nodes as well as leaf nodes. * This architecture results in a specific utilization of storage: it is described as a system that "wastes space" relative to other optimized structures.
Search Characteristics: * Searching within a B-tree is identified as being more "difficult" compared to B+ trees because data is dispersed throughout both internal and leaf nodes. * A defining feature of the B-tree is that it does not store redundant search keys; every key exists in exactly one location within the tree.
B-Tree Construction Example (Order 3)
Objective: Create a B-tree of order for the following data sequence: . (Note: One referenced sequence also includes the value , but the step-by-step procedure follows the previous list).
Rule for Order 3: Each node can hold a maximum of , which equals key values.
Step-by-Step Construction: * Step 1: Insert * The values are inserted in ascending order. * Node state: . * Step 2: Insert * The sequence becomes . * As only key values are permitted per node, the middle value () must move up to a new root level. * Resulting Tree: * Root: * Left Child: * Right Child: * Step 3: Insert * The value is placed in the left child following the value . * Tree State: Root , Children and . * Step 4: Insert * The sequence for the left child becomes . * The middle element () moves up to the root. * Resulting Tree: * Root: * Left of 12: * Middle (between 12 and 20): * Right of 20: * Step 5: Insert * The value is placed in the right child node alongside . * Tree State: Root , Leaves , , and . * Step 6: Insert * The sequence in the right leaf becomes . * The middle value () moves up to the root. * This creates a root sequence of . Because this exceeds the limit of keys, the middle value of this new root () must move up to become the new primary root. * Final B-Tree Structure: * New Root: * Level 1 Children: Left , Right * Leaf Nodes (Level 2): * Under 12: and * Under 40: and
Fundamentals of B+ Tree Data Structures
Storage Configuration: * In a B+ tree, data must be stored exclusively in the leaf nodes. * The internal nodes serve only as indexes (search keys) to guide the search process.
Efficiency and Search: * This structure does not waste space compared to a standard B-tree. * Searching is simplified and "very easy" because all actual data is guaranteed to be found at the leaf level. * A key distinction is that the B+ tree stores redundant search keys; a key appearing in an internal node will also appear in a leaf node.
B+ Tree Construction Example (Order 5 Pointers)
Objective: Construct a B+ tree for the following data sequence: .
Parameters: * Number of pointers per node: . * Maximum key values allowed per node: .
Step-by-Step Construction: * Step 1: Insert * Insert keys in ascending order. * Node state: . * Step 2: Insert * The sequence becomes . * The middle key () moves up to the root level. * In accordance with B+ tree rules, the middle key remains in the leaf as well. * Resulting Tree: * Root: * Left Leaf: * Right Leaf: * Step 3: Insert * The values are added to the left leaf in ascending order. * Leaf state: . * Step 4: Insert * The sequence for the left leaf becomes . * The middle key () moves up to join the root. * Final B+ Tree Structure: * Root Node: * Leaf Nodes: * First Leaf: * Second Leaf: * Third Leaf: