Indexing & File Organization MCQs for NSCT

By the NSCT Exam Editorial Team · Updated 2026-11-24 · Facts checked against official sources on 2026-11-24

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:

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.

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

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

Interactive quiz loading. The first 10 questions are shown below.

  1. In Elmasri-Navathe's terms, what is a primary index?

    1. An index on the ordering key field of a file that is physically sorted on that key
    2. Any index built on the primary key, whether or not the file is sorted on it
    3. An index on a non-ordering field with one entry per record
    4. An index on an ordering field that is not a key
    Show answer

    Answer: A. An index on the ordering key field of a file that is physically sorted on that key

    Elmasri-Navathe define a primary index on the field that both orders the file and is unique (the ordering key). It has one entry per data block, pointing at the block's first (anchor) record. An index on an ordering non-key field is a clustering index; one on a non-ordering field is a secondary index.

  2. What is the difference between a dense and a sparse index?

    1. A dense index is stored in RAM; a sparse index is stored on disk
    2. A dense index uses hashing; a sparse index uses a B+ tree
    3. A dense index is always clustered; a sparse index is always non-clustered
    4. A dense index has an entry for every search-key value (or record); a sparse index has entries for only some, such as one per block
    Show answer

    Answer: D. A dense index has an entry for every search-key value (or record); a sparse index has entries for only some, such as one per block

    Density is about how many entries the index has. Dense: one entry per search-key value (Silberschatz) or per record (Elmasri). Sparse: entries for only some values, typically one per data block, which works only when the file is sorted on that key.

  3. In a B+ tree index, where are the pointers to data records stored?

    1. In every node, internal and leaf
    2. Only in the leaf nodes, which are also linked to each other in key order
    3. Only in the root node
    4. Only in the internal nodes
    Show answer

    Answer: B. Only in the leaf nodes, which are also linked to each other in key order

    B+ tree internal nodes hold only keys and child pointers, to guide the search. All record pointers sit in the leaves, and each leaf points to the next, so a range query finds its first key and then walks along the leaf level.

  4. For which kind of query is a hash index a poor choice?

    1. A range query such as salary BETWEEN 40000 AND 60000
    2. An equality query such as id = 1042
    3. Looking up one customer by email address
    4. A join on equal key values
    Show answer

    Answer: A. A range query such as salary BETWEEN 40000 AND 60000

    A hash function scatters neighbouring keys into unrelated buckets, so there is no order to walk for a range. Hashing is excellent for equality look-ups, typically about one bucket access, but a range query needs an ordered structure such as a B+ tree.

  5. A file is physically ordered on dept_no, which is not unique. In Elmasri-Navathe's terms, what is an index on dept_no called?

    1. A primary index
    2. A secondary index
    3. A hash index
    4. A clustering index
    Show answer

    Answer: D. A clustering index

    When the ordering field is not a key, Elmasri-Navathe call the index a clustering index: one entry per distinct value, pointing to the first block holding that value. A primary index needs the ordering field to be a key.

  6. How many primary or clustering indexes can a single data file have?

    1. Exactly two
    2. One per key attribute
    3. Any number
    4. At most one
    Show answer

    Answer: D. At most one

    Both index types rely on the file being physically sorted on the indexed field, and a file can be sorted in only one way. So it has at most one of them, plus any number of secondary indexes. This is why a SQL table can have only one clustered index.

  7. Why is a secondary index on a key field always dense?

    1. Secondary indexes are always stored as hash tables
    2. Block anchors make it dense automatically
    3. The file is not ordered on that field, so every record needs its own index entry
    4. A secondary index stores the whole record in each entry
    Show answer

    Answer: C. The file is not ordered on that field, so every record needs its own index entry

    A sparse index works only when records between two index entries are known to be in order, which needs the file sorted on that field. A secondary index is on a non-ordering field, so records with any value can sit anywhere, and each one needs its own entry.

  8. Why does a B+ tree usually have a higher fan-out than a B-tree for the same block size?

    1. Its internal nodes hold only keys and tree pointers, not data pointers, so more entries fit in a block
    2. Its leaves are linked together
    3. It allows nodes to be less than half full
    4. It stores keys in sorted order
    Show answer

    Answer: A. Its internal nodes hold only keys and tree pointers, not data pointers, so more entries fit in a block

    A B-tree node holds a data (record) pointer with each key, which uses space. B+ tree internal nodes drop those pointers, so each block fits more keys and children. Higher fan-out means fewer levels and fewer block reads per search.

  9. In extendible hashing, when does the directory double in size?

    1. Every time any bucket overflows
    2. When a full bucket must split and its local depth equals the global depth
    3. When the file has twice as many records as buckets
    4. When a bucket becomes empty
    Show answer

    Answer: B. When a full bucket must split and its local depth equals the global depth

    If the full bucket's local depth is less than the global depth, several directory entries already point to it, so it can split without changing the directory. Only when local depth equals global depth must the directory double, raising the global depth by 1.

  10. What distinguishes linear hashing from extendible hashing?

    1. Linear hashing never allows overflow buckets
    2. Linear hashing doubles a directory on every overflow
    3. Linear hashing supports range queries efficiently
    4. Linear hashing has no directory; buckets are split one at a time in a fixed order
    Show answer

    Answer: D. Linear hashing has no directory; buckets are split one at a time in a fixed order

    Linear hashing grows the file gradually: a split pointer moves through the buckets in order, splitting the next one whenever the load rises, and it uses hash functions h_i and h_(i+1). It needs no directory, but it uses overflow chains until a bucket's turn to split comes.

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.