retagged by
22,442 views
47 votes
47 votes
Consider a database implemented using $\text{B+}$ tree for file indexing and installed on a disk drive with block size of $\text{4 KB}$. The size of search key is $\text{12 bytes}$ and the size of tree/disk pointer is $\text{8 bytes}$. Assume that the database has one million records. Also assume that no node of the $\text{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 _______
retagged by

3 Answers

Best answer
76 votes
76 votes

Given,

  1. Search Key: $12$ bytes
  2. Tree Pointer: $8$ bytes
  3. Block Size: $4096$ bytes
  4. Number of database records: $10^6$

Since it's a $B^+$ tree, an internal node only has search key values and tree pointers. Let $p$ be the order of an internal node. Hence,

$p(8) + (p-1)(12) \leq 4096$

which gives $p \leq 205.4$.

Therefore $p = 205$

Now, $$\small \begin{array}{c|c|c|c} \hline \text{Level} & \text{Nodes} & \text{Keys} & \text{Pointers} \\\hline  1 & 1 & 204 & 205 \\ 2 & 205 & 204 \times 205 & 205^{2} \\ 3 & 205^{2} & 204 \times 205^{2} & 205^{3} \\\hline \end{array}$$

Level $3$ alone has approximately $8.5\times10^6$ entries. So we can be sure that a $3$-level $B+$ tree is sufficient to index $10^6$ records.

So to access any record (in the worst case), we need $3$ block access to search for the record in the index along with $1$ more access to actually access the record.

Hence, $4$ accesses are required. 

edited by
13 votes
13 votes

Here, In the question size of tree pointer and disk pointer is the same. So, the order of leaf and non-leaf will be the same.

Suppose the order of non-leaf node = P. Where P= no. of tree pointer contains by a node.

So,

( P x 8 ) + ( (P-1) * 12) = 4096

8P+12P-12=4096

20P=4108

P=205.4

So P=205.

Now we will know the order of the node and that is 205.

Here, the database file contains 1 million records.

so, No. of search key at the last level should be 1 million. We require minimum no. of disk access so node of the B+ tree should be fully filled. 

 

Level No . of Child Pointer No. of Search Key
1 205 204
2 $205^{2}$ 205 * 204
$205^{3}$ $205^{2}$ * 204 =8573100

So, for 1 million records total 3 level requires.

Now after getting search key in B+ tree, one extra disk access requires to access a record.

So Total 3+1=4 minimum disk access requires.

1 votes
1 votes

In B+ trees there are n-1 search keys for n pointers.
so here in this question search keys is of size 12 Bytes where disk pointers is of size 8 bytes now.
 [ 8 * n ] + [12 * (n-1)] <= 4096 …….this is because block size is 4KB and in most outer block we will be having only one block which will have index overhead of inner blocks 
8n + 12n – 12 = 4096
20n = 4084
n = 204.2
so most outer block can have 205 nodes.i.e 204 search keys.

for inner one for each search key there will 205 nodes so at second level 204 * 205 = 41820 
at 3rd level 41820 * 205 = 8573100 
now 8573100  is way bigger than 1 million so we can easily put 1 million records in 3rd level so we need 3 block access to get the node pointer and 1 block access to retrive DATA.

so total 4 Block Access.

edited by
Answer:

No related questions found