A B-tree used as an index for a large database table has four levels including…

2023

A B-tree used as an index for a large database table has four levels including the root node. If a new key is inserted in this index, then maximum number of nodes that could be newly created in the process is

  1. A.

    5

  2. B.

    4

  3. C.

    3

  4. D.

    2

Attempted by 140 students.

Show answer & explanation

Correct answer: A

In a B-tree, insertion always starts at a leaf. A node that would exceed its maximum key capacity is split into two nodes, and its median key is pushed up into the parent. If that parent also overflows, it splits too, and the cascade can continue upward. The root is the one node on this path with no parent above it, so when the root itself overflows, the tree cannot push the median key up any further -- instead, it creates a brand-new root above the old one to hold that key, which is the only situation in which a completely new top level is added.

This B-tree currently has four levels, so the insertion path from the root down to the affected leaf passes through four existing nodes. In the worst case, every node along this path is already full, so the cascade of splits reaches all the way up: the leaf splits, its parent splits, the next node up splits, and finally the old root splits too -- one new sibling node from each of these four existing levels. Because the split that reaches the old root has nowhere further to push its median key, the tree also builds the extra new root node described above.

In general, a B-tree with h levels can create at most h new sibling nodes from level-by-level splitting, plus one additional new root when the split cascade reaches the top -- a maximum of h + 1 newly created nodes for a single insertion. With h = 4 levels here, that maximum works out to five newly created nodes.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Nta Ugc Net Paper 2

Loading lesson…