# B and B+ Trees

Question 1 |

Consider a B+-tree in which the maximum number of keys in a node is 5. What is the minimum number of keys in any non-root node? (GATE CS 2010)

1 | |

2 | |

3 | |

4 |

**B and B+ Trees**

**Discuss it**

Question 1 Explanation:

Since the maximum number of keys is 5, maximum number of children a node can have is 6. Bydefinition of B Tree, minimum children that a node can have would be 6/2 = 3. Therefore, minimum number of keys that a node can have becomes 2 (3-1).

Question 2 |

Which one of the following is a key factor for preferring B-trees to binary search trees for indexing database relations?

Database relations have a large number of records | |

Database relations are sorted on the primary key | |

B-trees require less memory than binary search trees | |

Data transfer form disks is in blocks. |

**B and B+ Trees**

**Discuss it**

Question 2 Explanation:

A disk block contains fairly large number of keys. Unlike BST where each node contains only one key, B-Tree is designed to contain large number of keys so that tree height is small.

Question 3 |

B+ trees are preferred to binary trees in databases because (GATE CS 2000)

Disk capacities are greater than memory capacities | |

Disk access is much slower than memory access | |

Disk data transfer rates are much less than memory data transfer rates | |

Disks are more reliable than memory |

**B and B+ Trees**

**Discuss it**

Question 3 Explanation:

Disk access is slow and B+ Tree provide search in less number of disk hits. This is primarily because unlike binary search trees, B+ trees have very high fanout (typically on the order of 100 or more), which reduces the number of I/O operations required to find an element in the tree.

Question 4 |

Which of the following is FALSE about B/B+ tree

B/B+ trees grow upward while Binary Search Trees grow downward. | |

Time complexity of search operation in B/B+ tree is better than Red Black Trees in general. | |

Number of child pointers in a B/B+ tree node is always equals to number of keys in it plus one. | |

A B/B+ tree is defined by a term minimum degree. And minimum degree depends on hard disk block size, key and address sizes. |

**B and B+ Trees**

**Discuss it**

Question 4 Explanation:

Asymptotic time complexity of both is of order logn.

Question 5 |

A B-tree of order 4 is built from scratch by 10 successive insertions. What is the maximum number of node splitting operations that may take place?

3 | |

4 | |

5 | |

6 |

**B and B+ Trees**

**GATE CS 2008**

**Discuss it**

Question 5 Explanation:

Insertion of 3 keys 10 20 30 Insertion of 4th key (1st split) 30 / \ 10*20 40 Insertion of 5th key no split To maximize splits, let us insert a value in a node that has key in access. Let us insert 5 30 / \ 5*10*20 40 Insertion of 6th key (2nd Split) To maximize splits, let us insert a value in a node that has key in access. Let us insert 6 8*30 / | \ 5 10*20 40 Insertion of 7th key To maximize splits, let us insert a value in a node that has key in access. Let us insert 15 8*30 / | \ 5 10*15*20 40 Insertion of 8th key (3rd Split) To maximize splits, let us insert a value in a node that has key in access. Let us insert 12 8*12*30 / / \ \ 5 10 15*20 40 Insertion of 9th key To maximize splits, let us insert a value in a node that has key in access. Let us insert 17 8*12*30 / / \ \ 5 10 15*17*20 40 Insertion of 10th key (4th and 5th Splits) To maximize splits, let us insert a value in a node that has key in access. Let us insert 13 12 / \ 8 15*30 / \ / | \ 5 10 13 17*20 40

Question 6 |

The order of a leaf node in a tree B+ ? is the maximum number of (value, data record pointer) pairs it can hold. Given that the block size is 1K bytes, data record pointer is 7 bytes long, the value field is 9 bytes long and a block pointer is 6 bytes long, what is the order of the leaf node?

63 | |

64 | |

67 | |

68 |

**B and B+ Trees**

**GATE-CS-2007**

**Discuss it**

Question 6 Explanation:

Disk Block size = 1024 bytes Data Record Pointer size, r = 7 bytes Value size, V = 9 bytes Disk Block ptr, P = 6 bytesLet order of leaf be m. A leaf node in B+ tree contains at most m record pointers, at most m values, and one disk block pointer.r*m + V*m + p <= 1024 16m <= 1018 m =< 63

Question 7 |

The order of an internal node in a B+ tree index is the maximum number of children it can have. Suppose that a child pointer takes 6 bytes, the search field value takes 14 bytes, and the block size is 512 bytes. What is the order of the internal node?

24 | |

25 | |

26 | |

27 |

**B and B+ Trees**

**GATE-CS-2004**

**Discuss it**

Question 7 Explanation:

Key size = 14 bytes (given) Child pointer = 6 bytes (given)

We assume the order of B+ tree to be ‘n’.

Block size = (n - 1) * key size + n * child pointer 512 >= (n - 1) * 14 + n * 6 512 >= 14 * n – 14 + 6 * n n = (512 + 14) / 20 n = 526 / 20 n = 26.3 n = 26

Thus, option (C) is correct.

Please comment below if you find anything wrong in the above post.

Question 8 |

Consider the following 2-3-4 tree (i.e., B-tree with a minimum degree of two) in which each data item is a letter. The usual alphabetical ordering of letters is used in constructing the tree.
What is the result of inserting G in the above tree ?

A) B) C) D) None of the above

A | |

B | |

C | |

D |

**B and B+ Trees**

**GATE-CS-2003**

**Discuss it**

Question 8 Explanation:

Since the given B tree is 2-3-4 tree, there can be at-most 4 children or 3 keys.
In B Tree insertion, we start from root and traverse till the leaf node where key is to be inserted. While traversing, if we find a a node which full, we split it. When we insert G, we find root itself is full, so we split it. When we come down to leftmost leaf, we find that the leaf is also full, so we split the leaf also.

Question 9 |

A B+ -tree index is to be built on the Name attribute of the relation STUDENT. Assume that all student names are of length 8 bytes, disk block are size 512 bytes, and index pointers are of size 4 bytes. Given this scenario, what would be the best choice of the degree (i.e. the number of pointers per node) of the B+ -tree?

16 | |

42 | |

43 | |

44 |

**B and B+ Trees**

**GATE-CS-2002**

**Discuss it**

Question 9 Explanation:

Size of 1 record = 8 + 4 = 12 Let the order be N. No. of index values per block = N - 1 (N - 1) 12 + 4 = 512 12N - 12 + 4 = 512 16N = 1009 N = 43.3333

Question 10 |

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 ________

4 | |

5 | |

6 | |

7 |

**B and B+ Trees**

**GATE-CS-2015 (Set 2)**

**Discuss it**

There are 16 questions to complete.