File organization and indexing (e.g. B and B+ trees)
How records are packed into blocks, primary, clustering and secondary indexes, multilevel indexes, and B and B+ trees: order, fan-out, height and block-access counts as GATE asks them.
An index is a sorted file of entries ⟨key, block pointer⟩. Entries are small, so many fit in a block: the index blocking factor is .
Index
Built on
Entries
Dense or sparse
Primary
Ordering key field of a sorted file
One per data block (block anchor)
Sparse
Clustering
Ordering non-key field
One per distinct value
Sparse
Secondary
Any non-ordering field
One per record (key field)
Dense
A dense index has an entry for every search-key value (every record); a sparse index has entries for only some. A file can have at most one primary or clustering index (it is sorted one way), but many secondary indexes.
Search cost with a single-level index: binary search the index blocks, then read one data block:
A secondary index usually has far more entries than a primary one (one per record instead of one per block), so it has more blocks, but it is still much faster than a linear scan of an unsorted file.
3. Multilevel indexes
Binary search halves the index each step. A multilevel index instead treats the index itself as a sorted file and builds a sparse index on it, repeating until the top level fits in one block. Each level divides by the fan-out , which is far bigger than 2.
If the first level has entries, it fills blocks. The next level has one entry per block of the level below, so each level shrinks by a factor of . The number of levels is
and a lookup reads one block per level plus the data block: accesses.
Example: and entries. Level 1 has 50 blocks, level 2 has 1 block, so and a lookup costs 3 accesses. Binary search on the 50-block single-level index would cost .
A static multilevel index is hard to keep sorted under inserts and deletes. B-trees and B+ trees are dynamic multilevel indexes: nodes are kept between half full and full, so the tree stays balanced and shallow.
4. B-trees
A B-tree of order (here: at most child pointers per node) satisfies:
Every node has at most children and at most keys, stored in sorted order.
Every internal node except the root has at least children; the root has at least 2 (unless it is a leaf).
All leaves are at the same level, so the tree is balanced.
Every key appears exactly once, in some node, together with its data (record) pointer.
Order from block size. A node holds block pointers, keys and record pointers:
Insertion: insert into the correct leaf. If it overflows (has keys), split it around the middle key, which moves up to the parent; splits can propagate to the root, which is the only way the height grows.
A B-tree can find a key in an internal node and stop early, but range scans must jump up and down the tree. Questions also use other definitions of order (for example minimum degree with maximum keys), so read the definition given in the question.
5. B+ trees
A B+ tree keeps all keys with record pointers in the leaves; internal nodes hold only keys and child pointers to guide the search. Leaves are linked left to right, so a range query finds the first key and then walks the leaf chain.
Order from block size (internal order = max children, leaf order = max key–record-pointer pairs):
The extra in a leaf is the next-leaf pointer. With no record pointers inside, an internal node has a higher fan-out than a B-tree node, so the tree is shallower.
Insertion: a leaf split copies the first key of the new right leaf up into the parent (it stays in the leaf); an internal split moves the middle key up.
B-tree
B+ tree
Record pointers
In every node
Only in leaves
Key repeated in internal nodes
No
Yes (as separators)
Fan-out for the same block
Lower
Higher
Range query
Awkward
Walk linked leaves
Search ends
Any level
Always at a leaf
Height bounds for levels (root = level 1, leaves = level ): maximum keys ; minimum keys for .
Internal nodes only guide the search; the leaves hold every key and are chained for range scans.
Formulas to remember
Blocking factor (unspanned)
Blocks in a file
Single-level index searchBinary search on index blocks, then one data block
Multilevel index levels = entries in the first level; lookup costs accesses
B-tree order
B+ tree internal order
B+ tree leaf order
Minimum children of a non-root internal nodeRoot needs at least 2
Common mistakes
Forgetting the next-leaf pointer when computing the B+ tree leaf order.
Using a B+ tree formula for a B-tree: B-tree nodes also hold a record pointer per key.
Rounding the order up; the inequality needs the largest integer that fits, so always round down.
Counting index entries per record for a primary index; it has one entry per data block.
Forgetting the final data-block access after the index search.
Mixing order definitions (max children, max keys, minimum degree); use the one the question defines.
Worked examples
Try each step yourself, then reveal the working.
Example 1: B+ tree order and height
numerical
Block size 2048 B, search key 12 B, block pointer 8 B, record pointer 10 B. Find the internal order and leaf order of a B+ tree, and the number of levels needed to index records if every node is full.
Step 1: Solve the internal-node inequality.
Try it on paper first.
Example 2: Primary vs secondary index cost
numerical
A file has 50,000 records of 200 B, sorted on key field K, in 2048 B blocks (unspanned). An index entry is 20 B (12 B key + 8 B pointer). Find the block accesses to find one record by (a) binary search on the file, (b) a single-level primary index on K, (c) a multilevel primary index, (d) a single-level secondary index on another key field.
Step 1: Blocking factor and file blocks.
Try it on paper first.
Example 3: Why B+ trees beat B-trees on fan-out
numerical
With the sizes of the first example (block 2048 B, key 12 B, block pointer 8 B, record pointer 10 B), find the order of a B-tree and compare it with the B+ tree internal order 103.
Step 1: Write the B-tree node inequality.
Try it on paper first.
Example 4: Minimum and maximum keys in a 3-level B+ tree
numerical
A B+ tree has internal order (at most 5 children) and leaf order (at most 4 keys per leaf). It has exactly 3 levels (root, one internal level, leaves). Find the maximum and minimum number of keys it can hold.
Step 1: Maximum: fill every node.
Try it on paper first.
Previous year questions
10 official GATE CSE questions on this topic, newest first.
10 questions: up to 4 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.
Mark as mastered
Loading your progress…
My revision notes
Notes written by the GATEiit team against the official GATE CSE syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.