If following sequence of keys are inserted in a B+ tree with K(=3) pointers :…

2017

If following sequence of keys are inserted in a B+ tree with K(=3) pointers :

8, 5, 1, 7, 3, 12, 9, 6

Which of the following shall be correct B+ tree ?

Attempted by 46 students.

Show answer & explanation

Key idea: For a B+ tree with K = 3 pointers, internal nodes can have up to 2 keys and leaves hold up to 2 keys. When a leaf overflows (3 keys temporarily), split it into two leaves (left gets 2 keys, right gets 1) and promote the first key of the right leaf into the parent. If an internal node overflows, split and promote the middle key to the parent.

  1. Insert 8: single leaf [8].

  2. Insert 5: leaf becomes [5,8] (fits).

  3. Insert 1: leaf temporarily [1,5,8] → split into leaves [1,5] and [8]; promote 8 to become the root key.

  4. Insert 7: goes to the left leaf [1,5] (since 7 < 8). Left leaf becomes [1,5,7] → split into [1,5] and [7]; promote 7 into the root. Root now has keys [7,8] with three children.

  5. Insert 3: goes to leftmost area (under 7). Left child leaf [1,5] becomes [1,3,5] → split into [1,3] and [5]; promoting 5 into the parent causes the internal node to overflow (would have three keys).

  6. Resolve the internal overflow: split the internal node and promote the middle key 7 to form a new root. Resulting structure after this step: root key [7]; left internal node with key [5] pointing to leaves [1,3] and [5]; right internal node with key [8] pointing to leaves [7] and [8].

  7. Insert 12: goes to rightmost leaf [8] → becomes [8,12] (fits).

  8. Insert 9: goes to leaf [8,12] → becomes [8,9,12] → split into [8,9] and [12]; promote 12 into the right internal node so it now has keys [8,12] with three children [7], [8,9], [12].

  9. Insert 6 (final): goes under the left internal node (since 6 < 7 but ≥ 5), into leaf [5] → becomes [5,6] (fits).

Final tree:

  • Root key: 7

  • Left internal node key: 5 with leaf children [1,3] and [5,6]

  • Right internal node keys: 8 and 12 with leaf children [7], [8,9], [12]

  • Leaf level (left to right): [1,3], [5,6], [7], [8,9], [12]

Conclusion: The correct image is the one that depicts a root key of 7, left leaves [1,3] and [5,6], and right leaves [7], [8,9], [12]. The previously blank solution has been replaced by this step-by-step reasoning and the final validated tree description.

Explore the full course: Tpsc Assistant Technical Officer