Introduction
A relation is stored as a file of records, and the file is stored on disk in fixed-size blocks (pages). The disk transfers whole blocks, so the cost of a database operation is measured in block accesses, not in record comparisons. File organization decides how records are packed into blocks and in what order the blocks hold them.
The quantities to compute are the blocking factor, the number of blocks a file needs, and the number of block accesses for a search under a given organization. These numbers are also the inputs to every index calculation in Indexing.
Prerequisites
None within the GATE syllabus. Familiarity with logarithms and with the idea of a hash function helps.
Core concepts
- Record: the stored form of one tuple. A fixed-length record has size bytes; variable-length records need a slotted-page layout or length fields.
- Block: the unit of transfer between disk and memory, size bytes.
- Blocking factor (records per block, unspanned): .
- Unspanned organization: a record never crosses a block boundary. Each block wastes bytes.
- Spanned organization: a record may continue in the next block, using a pointer at the end of the block. No space is wasted except the pointer; needed when .
- Number of blocks for records (unspanned): .

Three primary file organizations.
- Heap (unordered) file: a new record goes into the last block (or any block with space). Insertion is cheap; search is a linear scan.
- Sorted (sequential) file: records are kept in order of an ordering field. Search on that field is a binary search over blocks; insertion must keep the order, so it shifts records or uses overflow blocks and periodic reorganization.
- Hashed file: a hash function on a hash field maps each record to one of buckets (one block or a short chain of blocks). An equality search on the hash field reads one bucket.

How it works: access costs
Let be the number of blocks of the file. Costs count block accesses.
| Operation | Heap file | Sorted on the search field | Hashed on the search field |
|---|---|---|---|
| Equality search on a key, found | about for a uniformly located existing key (exactly for equally occupied blocks), worst | about | 1 if no overflow |
| Equality search, not found or non-key | about , plus following blocks for duplicates | 1 plus overflow blocks | |
| Range search | binary search, then consecutive blocks | (hashing destroys order) | |
| Insert | read and write the last block | find the place, then shift: about blocks read and written on average | read and write one bucket |
A search on a field other than the ordering or hash field gets no help from the organization: it is a scan of blocks.
Binary search over blocks. Read the middle block; if the key lies between its first and last record the search ends in that block, otherwise continue in one half. The worst case reads blocks. Many texts write this as ; the two agree unless is a power of 2, where the exact worst case is one more (for : 11 against 10). For this specified algorithm, use the exact worst case for . Treat only as an approximation or a different model explicitly prescribed by the question, never an exact default.
Mathematical explanation
Unspanned waste. With , the unused space per block is when , so the file wastes bytes, ignoring the partly filled last block.
Spanned size. With a pointer of bytes per block, the usable space is , and the file needs blocks.
Static hashing and overflow. If records are spread over buckets of capacity records, at least buckets are needed; real files allocate more (a fill factor below 1) because a skewed hash sends many records to one bucket and creates overflow chains, which cost extra accesses.
Worked examples
Example 1: blocking factor and file size. bytes, bytes, records.
- Unspanned: , blocks, waste bytes per block, bytes in all.
- Spanned with a 4-byte block pointer: blocks. Without any pointer it would be .
- In the spanned layout of Figure 1, block 1 holds records 1 to 10 (1000 bytes), the first 20 bytes of record 11, and the pointer; the other 80 bytes of record 11 start block 2.
Example 2: search costs on that file. Searching for a key value:
- Heap: about block accesses for a uniformly located existing key (exactly for equally occupied blocks), if it does not.
- Sorted on the key: , and the exact worst case agrees.
- Sorted on the key, but the search is on another field: .
Example 3: a non-key field on a sorted file. If the file is sorted on a non-key field and 25 records match, they sit in consecutive blocks: with they span 3 or 4 blocks depending on where the run starts, so the cost is a binary search that locates the first block of the run plus up to 3 further blocks.
Example 4: static hashing with overflow (Figure 2). , one block of 2 records per bucket, keys 12, 7, 22, 3, 17, 8, 15, 2 in that order. Bucket 0: 15. Bucket 2 receives 12, 7, 22, 17, 2: the home block holds 12, 7, a first overflow block holds 22, 17, and a second holds 2. Bucket 3: 3, 8. Buckets 1 and 4 stay empty. A search for 2 reads 3 blocks; a search for 4 (not present) reads only bucket 4. The heap file of the same keys has 4 blocks and the sorted file holds .
Related material. Extendible hashing (Elmasri and Navathe 16.8; Korth 24.5, which spells it "extendable") avoids long overflow chains: a directory of pointers is indexed by bits of the hash value (the global depth), and each bucket records how many bits it really uses (its local depth). A full bucket with local depth below splits without touching the directory size; a full bucket with local depth doubles the directory first. Using the last bits of the key, capacity 2, and inserting 8, 3, 12, 5, 16 into an empty structure: 12 doubles the directory to (buckets , ); 5 joins ; 16 finds full twice, since , and end in 00, so the directory doubles to and then to . The result has global depth 3, 8 directory entries and 4 buckets: (bits 000), (100), an empty bucket for 010 and 110 (local depth 2), and for all odd keys (local depth 1). Korth indexes the directory by a prefix (the first bits) of the hash value instead of the last bits; the doubling and splitting rules are the same, but the buckets hold different keys, so use the bit order the question gives.
Important properties and observations
- Cost is in block accesses. Record comparisons inside a block are not counted in these cost models.
- Floors and ceilings: takes a floor, the block count takes a ceiling.
- Spanned records waste no space but a record may need two block reads.
- Sorted files help only for the ordering field; hashed files help only for equality on the hash field.
- Hashing gives no order, so range queries scan the file.
- The binary-search count convention ( or ) matters only when is a power of 2.
Common misconceptions.
- "." That is the unrounded byte-volume ratio; the pointer-free spanned count is ; the unspanned count is .
- "A sorted file speeds up every query." Only queries on its ordering field.
- "A hashed file needs exactly one access per search." Overflow chains add accesses.
GATE examination perspective
- Blocking factor and block count. Use , and , unspanned unless stated.
- Average and worst-case block accesses. Apply this to heap, sorted and hashed files.
- Binary search on a sorted file. Watch the rounding convention.
- Wasted space. Under unspanned organization.
- These counts feed directly into index questions in Indexing.
Summary
Sources
- A. Silberschatz, H. F. Korth, S. Sudarshan, Database System Concepts, 7th ed., McGraw-Hill, 2019 (2020 copyright), 13.2 File Organization, 13.3 Organization of Records in Files, 14.5 Hash Indices, 24.5 Hash Indices.
- R. Elmasri, S. B. Navathe, Fundamentals of Database Systems, 7th ed., Pearson, 16.4 Placing File Records on Disk, 16.6 Files of Unordered Records (Heap Files), 16.7 Files of Ordered Records (Sorted Files), 16.8 Hashing Techniques.