Indexing & File Organization MCQs for NSCT
Indexing and file organisation decide how records are laid out on disk and how the DBMS finds them without reading every block. The key tools are ordered files, single-level and multilevel indexes, B+ trees and hashing, and the measure that matters is the number of block accesses. Indexing & File Organization is topic 12 of the Databases area, which carries 10% of the NSCT according to HEC's Areas of Competencies. In 2026 candidates averaged 42.3% in Databases, per the HEC NSCT report and APP.
File organisation and block accesses
With r records of R bytes in blocks of B bytes (unspanned), the blocking factor is bfr = ⌊B/R⌋ and the file needs b = ⌈r/bfr⌉ blocks. Elmasri-Navathe's standard estimates:
| Access method | Block accesses |
|---|---|
| Linear search on a key (heap file) | b/2 on average, b if absent |
| Binary search (file sorted on the key) | ⌈log2 b⌉ |
| Single-level primary index | ⌈log2 bi⌉ + 1 |
| Multilevel index with t levels | t + 1 |
| Static hashing, no overflow | about 1 |
For r = 30,000, R = 100 and B = 1,024: bfr = 10, b = 3,000, linear search averages 1,500 reads and binary search needs 12.
Primary, clustering and secondary indexes
Elmasri-Navathe name single-level indexes by the field they use:
| Index | Field | Density |
|---|---|---|
| Primary | Ordering key field | Sparse: one entry per block (the block anchor) |
| Clustering | Ordering non-key field | Sparse: one entry per distinct value |
| Secondary | Any non-ordering field | Dense on a key: one entry per record |
A file can have at most one primary or clustering index, because it can be sorted only one way, but it can have many secondary indexes. Exam angle: Silberschatz uses "primary index" for any clustering index, even on a non-key, so read the stem's convention.
B+ trees
A B+ tree is a balanced, multilevel index. Internal nodes hold only keys and child pointers; leaves hold keys with record pointers and are linked left to right for range scans. Every leaf is at the same depth.
Node order (Elmasri-Navathe). With block size B, key size V, tree pointer P and record pointer Pr:
- Internal: p × P + (p − 1) × V ≤ B
- Leaf: p_leaf × (V + Pr) + P ≤ B
For B = 512, V = 10, P = 6 and Pr = 7, p = 32 and p_leaf = 29. A B-tree, which keeps a record pointer with every key, fits only 23 per node, which is why databases use B+ trees.
Occupancy (Silberschatz, n pointers per node). Non-root internal nodes have between ⌈n/2⌉ and n children; leaves hold between ⌈(n−1)/2⌉ and n − 1 keys. A look-up reads at most ⌈log⌈n/2⌉(N)⌉ nodes for N keys. When a leaf overflows it splits, keeping the first ⌈n/2⌉ keys, and the first key of the new leaf is copied up. When an internal node overflows, its middle key moves up. Exam angle: the tree gains a level only when the root splits.
Hashing
A hash file computes a bucket address from the key, for example h(K) = K mod M, so key 50 with M = 7 goes to bucket 1. Hashing gives about one block access for equality searches but cannot help range queries.
- Static hashing fixes M buckets, so overflow chains grow as the file grows. Choosing a prime M spreads keys that share a factor.
- Extendible hashing uses a directory indexed by the first d bits of the hash value (the global depth). A full bucket whose local depth is less than d splits without touching the directory; if its local depth equals d, the directory doubles.
- Linear hashing has no directory and splits buckets one at a time in a fixed order.
Exam angle: Elmasri-Navathe and Silberschatz index the extendible-hashing directory with high-order bits; some lecture notes use low-order bits, so check the question.
Clustered vs non-clustered indexes
A clustered index stores the rows themselves in index-key order, so a table can have only one. A non-clustered index is a separate structure of keys and row pointers, so a table can have many. For a range such as order_date BETWEEN ..., a clustered index reads a few consecutive blocks, while a non-clustered one may read one block per matching row. Exam angle: when a condition matches a large share of rows, a full scan can beat a non-clustered index.
Common traps
- Using b instead of b/2 for an average successful linear search on a key.
- Calling every primary-key index a "primary index" when the question follows Elmasri's ordering-field definition.
- Moving the separator key up on a leaf split. In a B+ tree, leaf splits copy it up; only internal splits move it.
- Doubling the extendible-hashing directory on every overflow, even when local depth < global depth.
Worked examples
Understanding. Which single-level index on a key field is always dense? Answer: a secondary index. The file is not sorted on that field, so every record needs its own entry.
Application. r = 12,000 records, R = 150 bytes, B = 2,048 bytes, sorted on a 10-byte key, with 6-byte block pointers. How many block accesses does a primary-index search need? Answer: 4. bfr = 13 and b = 924. Index entries are 16 bytes, so bfri = 128 and bi = ⌈924/128⌉ = 8. Cost = ⌈log2 8⌉ + 1 = 4.
Analysis. Silberschatz's B+ tree with n = 5 (at most 4 keys per leaf). Insert 5, 10, 15, 20, 25 and 30 into an empty tree. What is the final tree? Answer: root [20] over leaves [5 10 15] and [20 25 30]. Inserting 25 overflows the leaf to five keys; the first ⌈5/2⌉ = 3 stay and 20 is copied up to a new root. Then 30 joins the right leaf.
Practise
The quiz below has 100 Indexing & File Organization questions, which you can filter by tier and difficulty.
Practise: 100 questions
FAQs
What is the difference between a B-tree and a B+ tree?
A B-tree stores record pointers in every node, so a search can stop at an internal node. A B+ tree keeps record pointers only in the leaves and links the leaves together. Its internal nodes therefore fit more keys, which gives higher fan-out, fewer levels and efficient range scans. Database indexes are almost always B+ trees.
When should I use hashing instead of a B+ tree?
Use hashing when queries are almost all equality look-ups on one attribute, such as fetching a session by ID, because it needs about one block access. Use a B+ tree when you also need ranges, sorting or prefix searches, since it keeps keys in order at a cost of a few levels per look-up.
What is the difference between a dense and a sparse index?
A dense index has an entry for every search-key value (or every record), so it works on any file. A sparse index has entries for only some values, usually one per data block, and works only when the file is sorted on that key. Sparse indexes are much smaller; dense ones can answer some queries from the index alone.
Next step
Continue with Query Processing & Optimization MCQs, go back to the Databases hub, or try a timed NSCT mock test.