∑GATE DA Atlas

File Organization and Indexing

Records, blocks and the blocking factor, heap, sorted and hashed file organisations with their access costs, primary, clustering and secondary indexes (dense vs sparse) and their sizes, multilevel indexes, B-trees and B+ trees (order from block size, height, search, insertion with splits, range queries), hash indexes (static and extendible), and how to choose an index.

Section 59 practice questions

Records, blocks and the blocking factor

Data on disk is read and written in blocks (pages). Because a block access costs far more than in-memory work, file and index performance is measured in block accesses.

blocking factor bfr=⌊BR⌋ (unspanned),blocks b=⌈rbfr⌉\text{blocking factor } \text{bfr} = \left\lfloor\frac{B}{R}\right\rfloor \text{ (unspanned)}, \qquad \text{blocks } b = \left\lceil\frac{r}{\text{bfr}}\right\rceil

for block size BB, record size RR and rr records. Spanned records may cross block boundaries (no wasted space); unspanned records may not.

File organisations

OrganisationHow records are placedEquality searchRange searchInsert
Heap (unordered)anywhere, usually at the endb/2b/2 average, bb if absentbbO(1)O(1)
Sorted (sequential)ordered on a key⌈log⁡2b⌉\lceil\log_2 b\rceil (binary search)binary search + scanexpensive (shift or overflow area)
Hashedblock = h(key)h(\text{key})~1 (+ overflow chains)bb~1
Clusteredrecords with equal cluster key stored togethervia indexscanmoderate

Indexes

An index is an auxiliary file of (search key, pointer) entries, much smaller than the data file, kept sorted (or hashed) for fast lookup.

IndexBuilt onDense/sparsePer file
Primarythe ordering key field of a sorted filesparse (one entry per block, the block's first key — the "anchor")at most one
Clusteringan ordering non-key fieldsparse (one entry per distinct value)at most one (instead of primary)
Secondaryany non-ordering fielddense (one entry per record or per value with a list of pointers)many

Multilevel indexes

Index the index: the first level is sorted, so build a sparse index over it, and so on, until one block remains. With index fan-out fof_o (entries per block), the number of levels is ⌈log⁡for1⌉\lceil\log_{f_o} r_1\rceil where r1r_1 is the number of first-level entries, and a lookup costs (levels + 1) block accesses. B+ trees are dynamic multilevel indexes.

B-trees and B+ trees

Balanced search trees with high fan-out, designed so each node is one disk block.

B-tree of order pp (max pp children):

  • every node has at most p−1p - 1 keys; every non-root node has at least ⌈p/2⌉\lceil p/2\rceil children (⌈p/2⌉−1\lceil p/2\rceil - 1 keys);
  • keys and their data pointers can live in any node;
  • all leaves are at the same depth.

B+ tree:

  • internal nodes hold only keys and child pointers (routing);
  • leaves hold every key with its data pointer, plus a pointer to the next leaf (sequential access);
  • because internal nodes store no data pointers, they fit more keys → larger fan-out → shorter trees.
30 | 60 5 12 25 30 41 52 60 75 90 every key appears in a leaf (with its record pointer); leaves are chained for range scans keys < 30 go left, 30 ≤ k < 60 middle, ≥ 60 right
A B+ tree: routing keys above, all data at the linked leaf level.

Order from block size: internal node with pp pointers of PP bytes and p−1p - 1 keys of KK bytes: pP+(p−1)K≤BpP + (p - 1)K \le B. Leaf with qq (key, record-pointer) pairs and one next-leaf pointer: q(K+Pr)+P≤Bq(K + P_r) + P \le B.

Height: with fan-out FF and NN keys, height ≈⌈log⁡FN⌉\approx \lceil\log_F N\rceil. With F=100F = 100, three levels index a million keys; four levels, a hundred million.

Operations:

  • Search: one node per level, O(log⁡FN)O(\log_F N) block reads.
  • Range query: search for the lower bound, then follow leaf links.
  • Insert: insert into the leaf; if it overflows, split it in two and push the middle (first key of the new right leaf) up to the parent; splits can propagate to the root, which is how the tree grows taller.
  • Delete: remove from the leaf; on underflow, borrow from a sibling or merge with it.

Hash indexes

  • Static hashing: MM buckets, h(k) mod Mh(k) \bmod M, overflow chains when buckets fill. Equality search ≈ 1–2 block accesses.
  • Extendible hashing: a directory of 2d2^d pointers indexed by the first dd bits of the hash; a full bucket splits and, if necessary, the directory doubles — no long overflow chains.
  • Linear hashing: buckets split one at a time in round-robin order.

Hash indexes support only equality predicates; range and ordered queries need a tree.

Choosing an index

Quick revision

Practice questions

GATE-style questions: 2 one-mark and 7 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.

Q1NAT2 marks

A file has 10,000 fixed-length records of 100 bytes each, stored unspanned in blocks of 1024 bytes. The number of blocks needed is ______.

Q2NAT2 marks

The file above (1000 blocks of 1024 bytes, ordered on its key) gets a primary (sparse) index with one entry per block. Each entry is a 9-byte key plus a 7-byte block pointer. The number of blocks occupied by the index is ______.

Q3NAT2 marks

In a B+ tree, an internal node occupies one 512-byte block. A search key takes 10 bytes and a child pointer 6 bytes; a node with pp pointers holds p−1p - 1 keys. The maximum number of child pointers (order pp) of an internal node is ______.

Q4MCQ1 mark

Compared with a B-tree, the main structural feature of a B+ tree is that

Q5NAT2 marks

A B+ tree indexes 1,000,000 records. Every leaf holds exactly 100 record pointers and every internal node has exactly 100 children. The number of levels in the tree (including the leaf level) is ______.

Q6MSQ2 marks

Which statements about indexes are correct?

One or more options are correct.

Q7MCQ1 mark

A sparse index contains

Q8NAT2 marks

An unordered (heap) file occupies 1000 blocks. For a search on a key that is known to exist, the average number of block accesses with linear search is ______.

Q9NAT2 marks

In a B-tree of order 5 (each node has at most 5 children), the minimum number of keys in a non-root node is ______.