File organisation, indexes and access cost
Count bytes before nodes, and nodes before I/Os. Distinguish a record pointer from a child-block pointer. Search cost depends on clustering, buffer contents and whether the query needs the data row after locating an index entry.
6.1 Records, blocks and file layouts
Past papers · CS 2014–2026 (23 papers): 1 question, 1 mark
A heap file keeps no search-key order; insertion is simple and a full scan reads its data blocks. A sorted file supports ordered lookup and range scans but incurs insertion/deletion maintenance. A hashed file places records by a hash function; it favours equality search, not ordered ranges. A slotted page stores offsets to variable-length records so a record can move within the page while its slot stays stable.
With unrestricted spanning and no per-fragment overhead, a tightly packed file needs blocks. Do not use that expression for records required to fit entirely in a block. A heap scan costs reads; a successful search for a uniformly located unique row averages about half a file, while an unsuccessful search reads all blocks. For an ordered array of blocks, ordinary binary search uses at most block probes when . Some questions explicitly prescribe instead; use that stated cost model. On a single-level ordered index of blocks, apply the given binary-search cost to , then add a data-block fetch only if retrieving the record is required.
6.2 Dense, sparse, clustered and secondary indexes
Past papers · CS 2014–2026 (23 papers): 4 questions, 6 marks
An index search key is an indexed attribute set; it need not be a candidate key. A dense index represents every search-key value, either with individual record entries or a value entry pointing to a list of matching records. A sparse index represents only selected values, typically the first key in each sorted data block. To find a missing exact entry in a sparse index, take the greatest indexed key not exceeding the target, then search the corresponding ordered region.
| Index organisation | Data order and use |
|---|---|
| Primary, textbook terminology | Data ordered on a unique key; often sparse, one anchor per block |
| Clustering, textbook terminology | Data ordered on a non-key field; entries locate matching groups |
| Secondary | Data not ordered on this search key; must represent every searchable value |
| Clustered, broader terminology | Physical row order follows or nearly follows index order, whether or not key values are unique |
A file has one physical ordering, but may have many secondary indexes. B+ trees can implement dense or sparse ordered indexes. A conventional hash index represents all searchable values: there is no “preceding key then sequential scan” shortcut for missing values. Sparse anchor indexing needs the underlying order; hashing does not provide it.
For a multilevel sparse index, make one upper-level entry per lower-level block and repeatedly apply the ceiling until one root block remains. If all index levels are uncached, a point lookup uses index reads and normally one data-block read. Merely identifying the candidate data block does not include that final read. A covering index can answer a query without a separate data fetch.
6.3 B trees and B+ trees
Past papers · CS 2014–2026 (23 papers): 3 questions, 3 marks
Both are balanced multiway search trees: all leaves are at the same depth. Keys within a node are sorted. In a B tree, data entries or record pointers can accompany keys in internal nodes and a successful search may finish there. In a B+ tree, internal keys guide navigation; data entries are in leaves, which are linked for ordered scanning. An internal separator may therefore also appear as a leaf key.
| Node rule using maximum fan-out | Ordinary B/B+ internal node |
|---|---|
| Maximum children | |
| Maximum separator keys | |
| Non-root minimum children | |
| Non-root minimum separator keys | |
| Internal root minimum | Two children and one separator |
In a B tree, every non-root leaf also holds between and data keys. The root can also be the only leaf; an empty tree is a special case. B+ leaf capacity is determined separately from internal fan-out; with the usual occupancy rule, a non-root leaf has at least entries. If a question explicitly defines a different minimum occupancy, use that definition.
An original B+ tree: separators direct the search, and linked leaves store all entries.
6.4 Node capacities from byte budgets
Past papers · CS 2014–2026 (23 papers): 2 questions, 4 marks · DA 2024–2026 (3 papers): 1 question, 1 mark
6.5 Height bounds and range I/O
Past papers · CS 2014–2026 (23 papers): 2 questions, 3 marks
For a clustered index, a long range often touches consecutive data blocks. An unclustered range may need a data-block read for each matching row in the worst case. A large range can therefore favour a full file scan over an index.
6.6 Insertions, splits, deletions and merges
Past papers · CS 2014–2026 (23 papers): 2 questions, 3 marks · DA 2024–2026 (3 papers): 1 question, 2 marks
Search the leaf, insert in sorted order, then repair any overflow upwards. In the separator convention used here, each internal key is the minimum key in its right child subtree; an equal key descends right. Follow the stated convention if a question uses a different one.
For a B+ leaf split, distribute data entries between two legal leaves and copy the right leaf's smallest key to the parent. The copied key remains in the leaf. For an internal split, promote the middle separator and remove it from the two resulting internal nodes. A root split creates a new root, increasing height by one. In a B tree, a promoted data key moves into the parent.
After deletion, first try borrowing from a sibling with spare occupancy, updating parent separators. Otherwise merge nodes and remove the obsolete parent separator/child pointer, possibly propagating underflow. A root with only one child is replaced by that child. A separator may need updating even if occupancy remains valid.
6.7 Hash and bitmap indexes
Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks · DA 2024–2026 (3 papers): 1 question, 2 marks
Static hashing fixes the bucket array and uses overflow handling when a bucket fills. Extendible hashing uses selected hash bits to index a directory; directory entries can share buckets. A bucket's local depth is the number of distinguishing bits it uses; global depth is the number used by the directory.
Repeated collisions can require repeated splits. A directory doubling does not double the number of physical buckets. In a bit-trie variant, create just the branches needed to distinguish colliding keys; do not assume a complete tree. Hash indexes accelerate equality and equijoins; they do not place nearby numerical values together for range queries.
A bitmap index keeps a bit vector over rows for each indexed value. Bitwise AND, OR and NOT combine predicates, with a separate null policy. It is especially useful for analytical queries over low-cardinality columns.
6.8 Join algorithms and external sorting
Past papers · CS 2014–2026 (23 papers): 1 question, 2 marks
Let be relation sizes in blocks, the outer row count and the number of available buffer blocks. The costs below count reads and necessary intermediate writes, exclude writing the final result, and assume inputs are not already cached.
With three buffers, compare and : the smaller relation should be outer. With more buffers, compute both orientations because ceiling effects matter. If one input fits entirely in the usable buffers, read each input once and join in memory.
A merge join on already sorted inputs scans them in about reads when duplicate-key groups fit the available buffers. Otherwise groups may need rescanning or temporary storage. Add sorting costs when inputs are unordered; avoid counting a pipelined final merge twice.
Last-minute recall
- Floor records per block; ceil blocks needed.
- A sparse index locates an ordered region, not every record separately.
- B+ internal capacity excludes record pointers.
- B+ leaves keep promoted separators; internal splits move a separator upward.
- Height counts edges here; root-to-leaf reads count nodes.
- Add a data-block read only when the requested result requires it.
- Global hash depth counts directory bits; local depth counts bucket bits.
- Query I/O costs depend on buffers, clustering and final-output conventions.