How records are stored in disk blocks (heap, sorted and hashed files), blocking factor and block-access cost, primary, clustering and secondary indexes, multilevel indexes, and B and B+ trees with order and height calculations.
B+ trees are balanced search trees and hashed files are hash tables on disk.
Logarithms, floor and ceiling
Every count of blocks, levels and node capacity uses them.
Concept notes
1. Records, blocks and blocking factor
Data is read from disk one block (page) at a time, so cost is measured in block accesses, not comparisons.
With block size bytes and fixed record size bytes (), the blocking factor is the number of records per block:
For a file of records, the number of blocks is
This is unspanned organisation: a record never crosses a block boundary, so bytes per block are wasted. In spanned organisation a record may continue in the next block (needed when ), and no space is wasted.
Use floor for how many fit, and ceiling for how many blocks are needed. Mixing them up is the commonest arithmetic error.
The same formulas apply to index files: an index entry is (search key, pointer), of size , so the index blocking factor (also the fan-out of a multilevel index) is .
2. File organisations
Organisation
How records are placed
Equality search on key (blocks)
Range search
Insert
Heap (unordered)
at the end
average, worst
full scan
cheap: last block
Sorted (sequential)
ordered on a field
by binary search
good: find start, then scan
costly: shift records or use overflow
Hashed
block chosen by
about 1 (plus overflow chain)
poor: full scan
cheap
A search on a non-key field of a heap must read all blocks, since there may be many matches.
Binary search on a sorted file works only for the ordering field.
Static hashing with buckets: gives the bucket; a full bucket uses overflow blocks, which lengthen searches. Dynamic schemes (extendible and linear hashing) grow the number of buckets as the file grows.
Hashing gives no help for range queries, because consecutive keys go to unrelated buckets.
When to use what: heap for bulk loading and full scans; sorted for range queries on one field; hashing for exact-match lookups.
An index is a sorted file of (key, pointer) entries. Being much smaller than the data file, it is binary searched in block accesses, plus 1 to read the data block.
Index
Built on
Entries
Dense or sparse
Per file
Primary
ordering key field of a sorted file
one per data block (block anchor)
sparse
at most one
Clustering
ordering non-key field
one per distinct value
sparse
at most one
Secondary
any non-ordering field
one per record (key field)
dense
many
A dense index has an entry for every search-key value (every record, for a key); a sparse index has entries for only some values, so it needs the file to be ordered on that key.
A file is physically ordered on one field only, so it can have either a primary or a clustering index, not both, plus any number of secondary indexes.
For a secondary index on a non-key field, each entry points to a block of record pointers (an extra level of indirection), or the index repeats the key once per record.
Cost with a single-level index: block accesses, where = number of index blocks.
4. Multilevel indexes and B+ trees
A multilevel index indexes the index. Level 1 has entries; each higher level has one entry per block of the level below. With fan-out , the levels shrink by a factor of until one block (the top level) remains. The number of levels is
and a search costs block accesses (one per level plus the data block).
A B+ tree is a dynamic multilevel index that stays balanced on insert and delete.
Internal nodes hold up to child pointers and keys; they only guide the search.
Leaves hold the keys with their record (data) pointers, and a pointer to the next leaf, so range queries scan along the leaves.
Every node except the root is at least half full: at least children for internal nodes. The root needs at least 2 children (unless it is a leaf).
All leaves are at the same depth.
Order from block size (block pointer , record pointer , key ):
internal:
leaf:
With internal levels above the leaves, a B+ tree with max fan-out has at most leaves.
A small B+ tree: the root's keys 30 and 60 split the leaves; every key appears in a leaf, and leaves are chained left to right.
5. B tree versus B+ tree
A B tree of order stores data pointers in every node, internal ones included; each key appears exactly once. A B+ tree keeps data pointers only in the leaves; internal keys are copies used for routing.
Feature
B tree
B+ tree
Data pointers
in all nodes
only in leaves
Key repeated?
no
internal keys also appear in leaves
Internal node fan-out
lower (each entry also holds a data pointer)
higher
Height for the same data
equal or more
equal or less
Equality search
may stop at an internal node
always reaches a leaf
Range query
in-order traversal of the tree
follow the leaf chain
B tree node of order : tree pointers, keys and data pointers: .
Because internal B+ tree nodes carry no data pointers, more keys fit per block, so the tree is shallower and needs fewer block accesses. This and the cheap range scans are why DBMSs use B+ trees for indexes.
Height bounds for a B+ tree with keys: more keys per node means fewer levels. The minimum height uses full nodes ( children); the maximum uses half-full nodes ( children, root with 2).
Formulas to remember
Blocking factor (unspanned)
Number of blocks
Binary search on a sorted file
Single-level index search
Index fan-out
Multilevel index levels
B+ tree internal node order
B+ tree leaf order
B tree node order
Common mistakes
Using ceiling for the blocking factor or floor for the number of blocks; it is floor for what fits and ceiling for what is needed.
Forgetting the +1 block access to read the data block after searching an index.
Counting one primary index entry per record; a primary index is sparse, with one entry per data block.
Using the leaf formula for internal nodes (or the other way round); leaves have record pointers plus one next-leaf pointer.
Confusing order as 'maximum keys' with order as 'maximum pointers'; read which one the question defines.
Assuming a file can have both a primary and a clustering index.
Worked examples
Try each step yourself, then reveal the working.
Example 1: Sorted file and primary index
numerical
A file has records of bytes, sorted on its key; block size bytes, unspanned. The key is 9 bytes and a block pointer 6 bytes. Find the block accesses to find a record by key (a) by binary search on the file, (b) through a primary index.
Step 1: Find the blocking factor and the number of blocks.
Try it on paper first.
Example 2: Turning it into a multilevel index
numerical
Continue the previous example: build a multilevel index on the 45-block primary index (fan-out 68). How many levels and how many block accesses?
Step 1: Build levels until one block remains.
Try it on paper first.
Example 3: Order of a B+ tree
numerical
Block size 512 bytes, key 10 bytes, block pointer 6 bytes, record pointer 7 bytes. Find the maximum number of child pointers in an internal node and of keys in a leaf of a B+ tree.
Step 1: Write and solve the internal-node inequality.
Try it on paper first.
Example 4: Choosing the right index
conceptual
A STUDENT file is physically sorted on roll_no (a key). Queries also look up students by email (unique) and by city (many per city). Which indexes can be built on roll_no, email and city?
Step 1: The ordering field.
Try it on paper first.
Previous year questions
3 official GATE DA questions on this topic, newest first.
10 questions: up to 3 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 DA syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.