25-Comp-B3 Data Bases and File Systems · December 2013
Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer) · Last updated
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.
(a) Equality search vs. range search. An equality search asks for the record(s) whose search-key value equals one specific value (e.g. "find the student with SID = 12345"); a range search asks for every record whose key falls between two bounds (e.g. "find all students with GPA between 3.0 and 4.0"), potentially returning many records. On a B+-tree, both start with the identical top-down traversal — comparing the target/lower-bound key against each internal node's separators to descend to the correct leaf — but they differ at the leaf level: an equality search stops once it finds (or fails to find) the matching key in that one leaf, while a range search continues scanning forward along the leaf-level linked list from that starting point, collecting every key up to the upper bound, hopping across leaf boundaries via the sibling pointers until the range is exhausted. This is precisely why B+-trees (unlike plain B-trees, which do not chain their leaves) are the standard database index: the same structure answers both query types efficiently, with range search cost proportional to the number of leaves the range actually spans plus one initial descent.
(b) Does insertion order affect the final B+-tree structure? Yes. Although the final set of keys stored in the leaves is always the same (a B+-tree is a valid search structure for any key set), the exact shape — which keys become internal separators, how deep the tree grows, and how the keys are grouped across leaves — depends on the sequence in which splits occur, and splits are triggered purely by insertion order. Question 1(c) inserted {18, 10, 7, 14, 8, 9, 21} in that specific order and produced a 3-level tree with leaves [7,8] | [9] | [10] | [14] | [18,21]. Inserting the exact same seven keys in sorted order (7, 8, 9, 10, 14, 18, 21) instead produces a different shape — the same 3-level height, but with leaves [7,8] | [9,10] | [14,18] | [21] — four leaves grouped differently, and different keys promoted as separators — because the overflow points fall at different moments. Both trees are equally valid (correct, balanced, and searchable), which is the point: B+-tree shape is a function of insertion history, not just of the final key set.
(c) Fill, insert, and delete on a partially specified B+-tree.
Given. Root (1 of 2 cells filled) → two internal nodes (each 1 of 2 cells filled) → four leaves [abc] | [acc] | [bb,bcd] | [bce,bxy], linked left to right, as shown (internal separators blank as given):
[Figure not reproduced: Fig. Q2c — the partially specified tree as given (internal separator cells blank). See the official exam paper.]
Find. (i) the missing separator keys; (ii) the tree after inserting "bbb"; (iii) the tree after then deleting "abc".
Approach. Every B+-tree internal separator equals the smallest key in the subtree immediately to its right (the standard "copy-up" invariant) — that alone determines the fill-in with no new keys added. Insertion and deletion then follow the same split/borrow/merge rules used throughout this subject.
[Figure not reproduced. See the official exam paper.]
| Stage | Root | Leaf chain |
|---|---|---|
| (i) filled | [bb] | abc | acc | bb,bcd | bce,bxy |
| (ii) + bbb | [bb] | abc | acc | bb,bbb | bcd | bce,bxy |
| (iii) − abc | [bcd] | acc | bb,bbb | bcd | bce,bxy |