25-Comp-B3 Data Bases and File Systems · December 2017
Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)
Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.
Part (a) — equality search vs. range search. An equality search asks for the record(s) matching one specific key value (e.g. "find the record with key = 18"): the tree is descended once, comparing the search key against each node's separators to choose a single child at every level, until a leaf is reached and its (one or few, if duplicates exist) matching entries are read directly — cost is O(log₀ N) node reads and no more. A range search asks for every record whose key falls between two bounds (e.g. "find all keys between 10 and 21"): the tree is descended once to locate the leaf holding the lower bound, exactly as for an equality search, but from there the search does not re-descend from the root for each additional match — it walks sideways along the leaf level using the leaf-to-leaf sibling pointers until a leaf value exceeds the upper bound. This sideways chain is precisely why B+-trees keep all data in the leaves linked in sorted order, unlike a plain B-tree that also stores data in internal nodes: a plain B-tree's range scan would have to interleave in-order tree traversal with data reads, markedly less efficient for sequential/range access than following one linked list.
Part (b) — does insertion order change the final tree? Yes. A B+-tree's shape is a byproduct of exactly when each split happens, and a split's timing depends on which keys have already accumulated in the leaf being inserted into — which in turn depends on the arrival order, not merely on the final key set. Question 1(c) inserted 18, 10, 7, 14, 8, 9, 21 in that (non-sorted) order and obtained root [14] over internal nodes [9, 10] and [18], with five leaves [7,8] ↔ [9] ↔ [10] ↔ [14] ↔ [18,21]. Inserting the SAME seven keys in ascending order (7, 8, 9, 10, 14, 18, 21) first overflows on the third key ([7,8,9] splits to [7,8] / [9]) and, after two more leaf splits and one root split, ends with root [14] over internal nodes [9] and [21] and only four leaves: [7,8] ↔ [9,10] ↔ [14,18] ↔ [21]. Same keys, same sorted leaf sequence, but different separators, a different number of leaves and different leaf occupancy. The one thing insertion order can never change is the sorted left-to-right order of the keys across the leaf chain, because that is the B+-tree's defining invariant; what varies is which keys are promoted as separators, how many nodes result, how full each one is and, for longer sequences, how many levels the tree reaches.
Part (c) — inserting alice, betty, carol, debbie, edith, zelda.
Given. An order-3 B+-tree (at most 2 keys and 3 children per node) on name keys, read from the figure: root [rick] → internal nodes [judy] and [tom]; [judy] → [bob | jane] and [mike | pete]; [tom] → [sol] and [vince]; ten leaves in sorted order: [abe,al] ↔ [bob,edie] ↔ [jane,joe] ↔ [judy,karen] ↔ [mike,nan] ↔ [pete,phil] ↔ [rick,rob] ↔ [sol] ↔ [tom,vera] ↔ [vince].
Find. The final tree after inserting alice, betty, carol, debbie, edith and zelda, one after another.
Approach. Route each key from the root using the separators (a key equal to a separator goes right), insert it into its leaf, and split upward as far as the overflow cascades. Five of the six keys fall between "al" and "jane", so they all land in the crowded left end of the [bob | jane] node and force repeated splits there; zelda goes to the far right.
| Item | Value |
|---|---|
| Root | [edie | rick], 3 children (was [rick], 2 children) |
| Level 2 | [bob] [judy] [tom] |
| Level 3 | [alice] [debbie] | [jane] [mike | pete] | [sol] [vince] |
| Leaf chain (13 leaves) | [abe,al] ↔ [alice,betty] ↔ [bob,carol] ↔ [debbie] ↔ [edie,edith] ↔ [jane,joe] ↔ [judy,karen] ↔ [mike,nan] ↔ [pete,phil] ↔ [rick,rob] ↔ [sol] ↔ [tom,vera] ↔ [vince,zelda] |
| Splits | 3 leaf splits (on alice, carol, debbie) and 3 internal splits (1 on alice, 2 on debbie); the root absorbs "edie" without splitting |
| Tree height | unchanged at 4 levels |