Sub topic 17
GATE Problem Patterns and Worked Strategies
What to assume
Assume that you know arrays, linked lists, binary search, balanced search trees, logarithms, and the meaning of a database record, key, pointer, and disk block. This chapter focuses on recognizing common GATE patterns and choosing the correct formula.
Most questions ask about one of these quantities:
- Records per data block.
- Number of data blocks.
- Index entries and index blocks.
- Tree order and height.
- Block accesses for search.
- Maximum or minimum keys after splits.
Pattern 1: Blocking and file access
For fixed-length, unspanned records, the blocking factor is:
BFR = floor(B / R)
Here, B is the block size and R is the record size. If the file contains r records, the number of data blocks is:
b = ceiling(r / BFR)
For example, let B = 1024 bytes, R = 100 bytes, and r = 30,000.
- BFR = floor(1024 / 100) = 10 records per block.
- b = ceiling(30,000 / 10) = 3,000 blocks.
A heap-file search may inspect about b / 2 blocks on average and b blocks in the worst case. A sorted file supports binary search, requiring about ceiling(log₂ b) block accesses. A hash file is usually best for equality search, but it does not naturally support sorted or range queries.
Pattern 2: Index size and access cost
A dense index has one entry for every record. A sparse primary index usually has one entry per data block.
If an index entry contains a key of V bytes and a pointer of P bytes, the index blocking factor is:
BFI = floor(B / (V + P))
For a sparse index with b entries, its number of blocks is:
bi = ceiling(b / BFI)
Searching this index may require ceiling(log₂ bi) block accesses. One additional access reads the target data block.
A multilevel index repeats the same calculation. Treat the blocks of one index level as the entries of the next level. Stop when the upper level fits in one block.
| Structure | Typical search cost | Best use |
|---|---|---|
| Heap file | Linear | Fast insertion |
| Sorted file | Logarithmic | Ordered scans |
| Hash file | Near constant for equality | Exact-match search |
| B+ tree | Logarithmic in height | Equality and range search |
Pattern 3: B-tree and B+ tree order
For a B-tree of order p, an internal node contains p pointers and p − 1 keys. Therefore:
pP + (p − 1)K ≤ B
The largest valid p is floor((B + K) / (P + K)).
For a B+ tree internal node, use the same inequality. For a leaf with one next-leaf pointer:
pₗ(K + Pr) + P ≤ B
Do not confuse P, a tree-child pointer, with Pr, a record pointer.
Pattern 4: Height and block accesses
A B+ tree search reads one block per level, including the leaf. If the root is already memory-resident, subtract one access.
For a height h tree with minimum fan-out m, estimate capacity using powers of m. For maximum capacity, use the maximum fan-out. Check whether the question counts keys, records, or pointers. These differ by one in internal nodes.
Worked strategy
For every numerical question:
- Write the block, key, record, and pointer sizes.
- Identify whether the node is internal or a leaf.
- Write the occupancy inequality before substituting numbers.
- Apply floor for capacity and ceiling for required blocks or levels.
- State what one block access represents.
Exercise
A data file has 2,400 records, a block holds 20 records, and a sparse index holds 10 entries per block. How many index blocks are required?
Show answer
The data file has 2,400 / 20 = 120 data blocks. The sparse index has 120 entries, so it needs ceiling(120 / 10) = 12 index blocks.