Question

With reference to the B+ tree index of order 1 shown below, the minimum number of nodes (including the Root node) that must be fetched in order to satisfy the following query: "Get all records with a search key greater than or equal to 7 and less than 15" is _____.

B+ tree index of order 1 with root, internal nodes, and linked leaf nodes
B+ tree index of order 1
Official answer and solution
Official answer
5
From
Official GATE 2015 answer key

Solution

Trace the B+ tree traversal path from root to leaf to find the initial search key, then follow leaf sibling pointers across the range.

The query asks for all records with key 7≤k<157 \le k < 15.

Step 1: Traverse the tree index to locate the lower bound key 77.

  • Fetch Node 1 (Root [9 | -]): Since 7<97 < 9, follow the left child pointer.
  • Fetch Node 2 (Internal node [5 | -]): Since 7≥57 \ge 5, follow the right child pointer.
  • Fetch Node 3 (Leaf node [5 | 7]): Key 77 is found in this leaf node.

Step 2: Traverse leaf sibling pointers to retrieve subsequent keys in the range [7,15)[7, 15):

  • Follow the sibling pointer to Fetch Node 4 (Leaf node [9 | 11]): Both keys 99 and 1111 satisfy 7≤k<157 \le k < 15.
  • Follow the sibling pointer to Fetch Node 5 (Leaf node [13 | 15]): Key 1313 satisfies 7≤k<157 \le k < 15. Key 1515 violates k<15k < 15, terminating the range scan.

Total nodes fetched = 1 (root)+1 (internal)+3 (leaves)=5 nodes1\text{ (root)} + 1\text{ (internal)} + 3\text{ (leaves)} = 5\text{ nodes}.

Final answer

5

Common trap

Omitting the root node or forgetting to count the final leaf node [13 | 15] where the terminating condition is detected.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2015 Computer Science and Information Technology (CS) Session 2
Question
16 of 65, printed as CS Q.6
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.