Questions 1–2 of 2
Answer: (C)
In a B-tree of order 4, a node holds at most 3 keys. When a 4th key arrives, the node splits: the middle key goes up to the parent and the other keys form two nodes. If the parent then overflows, it splits too.
Take keys inserted in ascending order, . This leaves half-empty nodes behind and forces splits as often as possible.
Inserting 1, 2, 3 fills one node. Then:
Key 4: the node splits, 2 goes up (split 1).
Key 5: the right leaf has room, no split.
Key 6: the right leaf [3, 4, 5] overflows and splits, 4 goes up (split 2).
Key 7: no split.
Key 8: the leaf [5, 6, 7] overflows and splits, 6 goes up (split 3).
Key 9: it goes into the leaf [7, 8], which has room, so no split.
Key 10: the leaf [7, 8, 9] overflows and splits, 8 goes up (split 4). The parent [2, 4, 6, 8] now has 4 keys, so it splits too, 4 becomes the new root (split 5).
Why 5 is the most: every leaf has at least 1 key, and each leaf split adds one leaf and puts one key in the internal level. With leaf splits there are leaves and internal keys, so , which gives . An internal split needs a node with 4 internal keys, so it can happen only when , and only once. So the splits are at most .
Answer: (C)
What is the result of inserting G in the above tree ?
Answer: (B)
The root is full, so split it: moves up and becomes the new root, with children and . The children of are and , and those of are and .
, so go to . , so go to . It is full, so split it: moves up into the parent, which becomes , and the leaf becomes and .
, so G goes into , giving .
The result is root , with children and , and the leaves , , , , . This is tree B.
Tree A has G inside an internal node with leaf . That comes from adding G to first and then splitting at G, which is not this procedure. Tree C keeps a root with 3 keys, but the full root must be split before going down.
Answer: (B)
Keep practising