NIMCET, GATE, CUET & CBSE test series are live — start practicing free
syllabuzAI

B Tree vs B+ Tree in DBMS: Order and Height | GATE CSE

Learn B-tree and B+ tree node structure, how to calculate order from block size, height bounds and level counts, and the key differences for GATE CSE DBMS.

8 min read

AS

Aman Singh

Updated 26 November 2026

On this page

Quick answer: B-trees and B+ trees are balanced multi-way search trees used as dynamic multilevel indexes. The order p is the maximum number of child (block) pointers in a node. A B-tree node holds up to p block pointers, p − 1 keys and p − 1 record pointers. A B+ tree keeps record pointers only in the leaves, and its leaves are linked for range scans. Every node except the root has at least ⌈p/2⌉ children, the root has at least 2, and all leaves sit at the same level. With the same block size, a B+ tree has a higher order, fewer levels and handles range queries much better.

Order calculations and height bounds for B and B+ trees are standard GATE numericals. This topic is part of the File Organization and Indexing chapter.

Why not a binary search tree or AVL tree?

A balanced binary tree keeps height O(log n), but each node holds a single key. Each level costs one disk block, so the tree has about log₂ n levels and most of every block is wasted. B and B+ tree nodes fill a whole block with many keys, so the height is about logₚ n with p in the tens or hundreds. That means far fewer block accesses.

B-tree

Node structure

Each node has up to p block (child) pointers, p − 1 keys and p − 1 record (data) pointers. The node must fit in one block:

p⋅Pb+(p−1)(K+Pr)≤Bp \cdot P_b + (p - 1)(K + P_r) \le B

Here Pb is the block pointer size, K the key size, Pr the record pointer size and B the block size.

Occupancy rules for order p

  • Every internal node except the root has at least ⌈p/2⌉ child pointers (so at least ⌈p/2⌉ − 1 keys) and at most p pointers (p − 1 keys).
  • The root has at least 2 child pointers (1 key), unless it is the only node.
  • All leaves are at the same level.

Search cost

  • Worst case: k + 1 block accesses for a tree with k levels (k index blocks plus the data block).
  • Best case: 2 block accesses (key found in the root, then the data block), because every node has record pointers.

B-trees are good for random access to single records but awkward for range scans, which need repeated tree traversal.

B+ tree

Node structure

Internal node: p block pointers and p − 1 keys, with no record pointers.

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

Leaf node: up to p_leaf (key, record pointer) pairs plus one pointer to the next leaf.

pleaf(K+Pr)+Pb≤Bp_{leaf}(K + P_r) + P_b \le B

Every key appears in a leaf. Keys in internal nodes are copies used only for routing. Because the leaves are linked, a range query is one search down to the first key followed by a sequential scan along the leaves.

Range query cost

To read x consecutive records: go down k levels to the first leaf, scan the leaves you need, then fetch the data blocks.

Worked example: finding the orders

Block size B = 1024 bytes, key K = 10 bytes, block pointer Pb = 8 bytes, record pointer Pr = 8 bytes.

Step 1: B-tree order.

8p+18(p−1)≤1024  ⇒  26p≤1042  ⇒  p≤40.078p + 18(p - 1) \le 1024 \;\Rightarrow\; 26p \le 1042 \;\Rightarrow\; p \le 40.07

So the B-tree order is 40.

Step 2: B+ tree internal order.

8p+10(p−1)≤1024  ⇒  18p≤1034  ⇒  p≤57.48p + 10(p - 1) \le 1024 \;\Rightarrow\; 18p \le 1034 \;\Rightarrow\; p \le 57.4

So the internal order is 57.

Step 3: B+ tree leaf capacity.

18 pleaf+8≤1024  ⇒  pleaf≤56.418\,p_{leaf} + 8 \le 1024 \;\Rightarrow\; p_{leaf} \le 56.4

So each leaf holds 56 keys.

Worked example: levels for one million records

Use the B+ tree above with completely full nodes.

Step 1: Leaves needed: ⌈1,000,000 / 56⌉ = 17,858.

Step 2: Next level up: ⌈17,858 / 57⌉ = 314.

Step 3: Next level: ⌈314 / 57⌉ = 6, and then 1 root.

So the tree has 4 levels (1, 6, 314 and 17,858 nodes). Reaching a record takes 4 + 1 = 5 block accesses.

Height bounds for a B-tree of order p with n keys

Let t = ⌈p/2⌉ and let height h mean h + 1 levels.

  • Maximum keys (all nodes full):

ph+1−1p^{h+1} - 1

  • Minimum keys: the root has 1 key and 2 children, and every other node has t − 1 keys and t children. Adding level by level gives:

2th−12t^{h} - 1

  • So for n keys:

h≤log⁡tn+12h \le \log_{t}\frac{n+1}{2}

which means the height is O(logₚ n).

Insertion and deletion

  • Insert: put the key in the right leaf. If the node overflows, split it and push the middle key to the parent. In a B+ tree leaf split the separator is copied up; in an internal split it is moved up. Splits can reach the root, and splitting the root is the only way the tree grows taller.
  • Delete: remove the key. If a node underflows, borrow from a sibling or merge with one, which may propagate upwards. The tree only gets shorter at the root.

B-tree vs B+ tree

PointB-treeB+ tree
Record pointersIn every nodeOnly in leaves
Order for the same block sizeLowerHigher (internal nodes have no record pointers)
Levels for the same block sizeMoreFewer
Keys storedEach key onceLeaf keys plus copies in internal nodes
Leaves linkedNoYes
Point queryCan stop early at an internal nodeAlways goes to a leaf
Range querySlowFast

If both trees have the same order p, the B-tree needs no more nodes or levels than the B+ tree, because the B+ tree repeats keys. With the same block size, though, the B+ tree has the higher order, so it has fewer levels and lower I/O cost.

Summary table

FormulaUse
pPb+(p−1)(K+Pr)≤BpP_b + (p-1)(K + P_r) \le BB-tree order
pPb+(p−1)K≤BpP_b + (p-1)K \le BB+ tree internal order
pleaf(K+Pr)+Pb≤Bp_{leaf}(K + P_r) + P_b \le BB+ tree leaf capacity
⌈p/2⌉\lceil p/2 \rceilMinimum children of a non-root node
ph+1−1p^{h+1} - 1Maximum keys, height h
2⌈p/2⌉h−12\lceil p/2 \rceil^{h} - 1Minimum keys, height h

Exam tips

  • Write the node-size inequality for the exact tree type and node type asked, then take the largest integer that satisfies it. Never round up.
  • Check whether the question defines order as maximum pointers or maximum keys. Most GATE questions use pointers, but read carefully.
  • For level counts, start from the leaves and divide upwards, using the leaf capacity first and the internal order after that.

Common mistakes

  • Putting record pointers in B+ tree internal nodes.
  • Forgetting the next-leaf pointer in the B+ tree leaf formula.
  • Mixing up order and keys per node. Keys per node = order − 1.
  • Rounding the order up instead of down.

Practice questions

Q1. Block size 512 bytes, key 10 bytes, block pointer 6 bytes, record pointer 8 bytes. Find the B+ tree internal order.

Answer:

6p+10(p−1)≤512  ⇒  16p≤522  ⇒  p≤32.66p + 10(p - 1) \le 512 \;\Rightarrow\; 16p \le 522 \;\Rightarrow\; p \le 32.6

The order is 32.

Q2. In a B-tree of order 5, what is the minimum number of keys in a non-root node?

Answer: ⌈5/2⌉ − 1 = 2.

Q3. What is the maximum number of keys in a B-tree of order 4 with 3 levels (height 2)?

Answer: 4³ − 1 = 63.

FAQs

What is the order of a B-tree?

It is the maximum number of child pointers a node can hold. A full node holds one fewer key than its order.

Why does a B+ tree have a higher order than a B-tree?

Its internal nodes store no record pointers, so more keys and child pointers fit in one block.

Why are B+ trees better for range queries?

All keys are in the leaves, and the leaves are linked. After you find the first key, the rest are read in order along the leaf chain.

What is the minimum number of children of a non-root B-tree node?

A non-root node of order p has at least ⌈p/2⌉ children. For order 5 that is 3 children and 2 keys.

How many levels does a B+ tree need for n records?

Divide n by the leaf capacity, then keep dividing by the internal order (rounding up each time) until you reach 1. The number of divisions plus one is the number of levels.

Conclusion

Write the node-size inequality for the tree type asked, solve for the largest integer, then use the order to count levels and access cost. Go back to the File Organization and Indexing chapter, revise indexing in DBMS, or review file organization.

Concept Check

MEDIUM

Consider a relation R(P, Q, R, S, T) and the set of functional dependency set {P → ST, S → Q, and T → R} if we project R (and therefore its FD sets onto schema R1 (P, Q, R). Then choose the correct option in the following?

Suggested for you