Skip to content
Official PYQ · 2020

GATE CS 2020 Q54 — File Organization and Indexing (B and B+ Trees)

Explain with AI
Consider a database implemented using B+B^+ tree for file indexing and installed on a disk drive with block size of 4 KB\text{4 KB}. The size of search key is 12 bytes\text{12 bytes} and the size of tree/disk pointer is 8 bytes\text{8 bytes}. Assume that the database has one million records. Also assume that no node of the B+B^+ tree and no records are present initially in main memory. Consider that each record fits into one disk block. The minimum number of disk accesses required to retrieve any record in the database is _______
View worked solution

Answer: 4

To find the minimum number of disk accesses required to retrieve any record, we need to minimize the height of the B+B^+ tree by assuming all nodes are filled to their maximum capacity.

1. Calculate the order of non-leaf nodes (pp):

A non-leaf node of order pp contains at most pp pointers and p−1p-1 keys. Given:

  • Block size (BB) = 4 KB=4096 bytes4\text{ KB} = 4096\text{ bytes}
  • Key size (KK) = 12 bytes12\text{ bytes}
  • Pointer size (PP) = 8 bytes8\text{ bytes}

p⋅P+(p−1)⋅K≤Bp \cdot P + (p-1) \cdot K \le B

p⋅8+(p−1)⋅12≤4096p \cdot 8 + (p-1) \cdot 12 \le 4096

20p−12≤4096  ⟹  20p≤4108  ⟹  p≤205.420p - 12 \le 4096 \implies 20p \le 4108 \implies p \le 205.4

Thus, the maximum order of a non-leaf node is p=205p = 205.

2. Calculate the maximum capacity of leaf nodes (dd):

A leaf node contains record pointers, keys, and one next-leaf pointer:

d⋅(K+P)+P≤Bd \cdot (K + P) + P \le B

d⋅(12+8)+8≤4096d \cdot (12 + 8) + 8 \le 4096

20d≤4088  ⟹  d≤204.420d \le 4088 \implies d \le 204.4

Thus, the maximum number of records indexed per leaf node is d=204d = 204.

3. Determine the minimum height of the B+B^+ tree:

The database has 10610^6 records.

  • Number of leaf nodes: ⌈106/204⌉=4902\lceil 10^6 / 204 \rceil = 4902 nodes
  • Level 2 (parents of leaves): ⌈4902/205⌉=24\lceil 4902 / 205 \rceil = 24 nodes
  • Level 3 (Root): ⌈24/205⌉=1\lceil 24 / 205 \rceil = 1 node

The minimum height of the B+B^+ tree is 33 levels.

4. Total Disk Accesses:

To retrieve a record, we must access:

  1. 33 disk blocks to traverse the B+B^+ tree (Root →\rightarrow Intermediate →\rightarrow Leaf).
  2. 11 disk block to fetch the actual data record.

Total disk accesses = 3+1=43 + 1 = 4.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore File Organization and Indexing (B and B+ Trees) questions