IAE Academy

GATE DA

File organisation and indexing

File organisation decides how records are laid out in disk blocks, and an index is an extra, smaller file that shortens the search for a record. GATE questions turn on block arithmetic: blocking factor, number of blocks, index levels, and B-tree or B+ tree order, height and block accesses. Most answers are counts of disk-block accesses, reached through blocking factors, index sizes and tree orders, so the habit to build is stating the block, record, key and pointer sizes first and counting carefully with floors and ceilings.

3 previous-year questions · 3 solved · 6 practice questions

Records, blocks and the blocking factor

A file is a sequence of records stored in fixed-size disk blocks. The cost of a database operation is counted in block accesses, because one block transfer costs far more than any in-memory work on it. Buffering and caching are ignored unless the question says otherwise.

Convention used throughout: block size , record size , key size , block pointer size and record pointer size are all in bytes. Records are unspanned (a record never crosses a block boundary) and fixed-length unless the question says otherwise. is the number of records and the number of data blocks.

BLOCKING FACTOR (UNSPANNED)

Records per block. The floor is essential: with unspanned records the leftover bytes in each block are unused.

NUMBER OF DATA BLOCKS

Blocks needed for records; round up because a partly filled last block still occupies a block.

With spanned records a record may continue into the next block, so (ignoring the pointer that links a record's pieces) no space is wasted and . Use this only when the question says records are spanned.

File organisations: heap, sorted and hashed

A heap (unordered) file keeps records in insertion order. A sorted (ordered) file keeps them physically ordered on an ordering field. A hashed file places each record in a bucket (a block or group of blocks) chosen by a hash function applied to the hash field.

Operation (in block accesses)

Heap

Sorted

Hashed

Equality search on a unique key (the organising field for sorted and hashed files)

on average, worst

(binary search)

About 1 (more if the bucket has overflow blocks)

Range search on the organising field

(scan everything)

plus the further blocks holding the range

(hash order is unrelated to key order)

Search on any other field

; on average if the value is unique and present

; on average if the value is unique and present

; on average if the value is unique and present

Insert

About 1 to 2 (read and write the last block)

Costly: find the place, then shift later records, about blocks read and written on average

About 1 to 2 (find the bucket, write)

Delete

Find the record, then rewrite its block

Find, then rewrite (or mark as deleted)

Find in the bucket, then rewrite

BINARY SEARCH ON A SORTED FILE

Applies only to the field the file is sorted on, and counts block accesses, not record comparisons. This is the usual convention in problems; the strict worst case of binary search is , which is one more only when is a power of 2. Follow the convention the question states.

EXAM TIP

A sorted file is fast only for the field it is sorted on. A search on any other field is a full scan of blocks (average if the value is unique and found). A file can be physically ordered on only one field.

Primary, clustering and secondary indexes; dense and sparse

An index is a separate file of entries , kept sorted on the key value, so it can be searched by binary search and is much smaller than the data file. An index entry has size (or when the entries hold record pointers, as a dense secondary index often does; use the sizes the question gives), and the index blocking factor (also the fan-out) is the number of entries per index block.

Index type

Built on

Data file

Entries

Primary

Ordering key field

Ordered on that field

Sparse: one entry per data block (the block's first key, the block anchor)

Clustering

Ordering non-key field

Ordered on that field

One entry per distinct value, pointing to the first block holding it

Secondary

A field the file is not ordered on (key or non-key)

Any order

Dense: one entry per record for a key field; for a non-key field, one entry per record, or one per distinct value pointing to a block of record pointers (an extra level of indirection)

A file can have at most one primary or clustering index (not both), because the file can be physically ordered on only one field. It can have many secondary indexes.

A dense index has an entry for every search-key value (or every record). A sparse index has entries for only some values, typically one per block. A sparse index needs the data to be ordered on the indexed field; to search it, find the last index entry whose key is less than or equal to the search key, then read that data block.

INDEX BLOCKING FACTOR (FAN-OUT)

Entries per index block, where an entry is a key plus a block pointer (replace by if the entries hold record pointers).

SINGLE-LEVEL INDEX SIZE

Dense: one entry per record. Sparse primary index: one entry per data block. A clustering index on a field with distinct values needs blocks.

SEARCH WITH A SINGLE-LEVEL INDEX

Binary search over the index blocks (same convention as for a sorted file), plus one access to fetch the data block. A non-key secondary index with a level of indirection adds one more access for the block of record pointers.

Multilevel indexes

If the first-level index is itself large, build a sparse index on the index: the second level has one entry per first-level block, and so on until a level fits in one block (the top). The search then reads exactly one block per level, with no binary search. This idea, applied with room left in nodes for insertion, gives the B-tree and B+ tree.

  1. Compute the first-level index blocks (dense: ; sparse primary: ).

  2. Each next level has blocks.

  3. Stop at the level that has 1 block. The number of levels is .

  4. Block accesses for a search is (one per index level, plus the data block).

MULTILEVEL INDEX LEVELS AND COST

is the fan-out, the number of first-level entries and the number of first-level blocks. The first form is valid for (for , ); the second for .

EXAM TIP

Compare the two ways of searching a first-level index: binary search costs index-block accesses, a multilevel index costs . The base is the fan-out, so the saving is large when is large.

WORKED EXAMPLE

A file has records of bytes, block size bytes, key size bytes and block pointer bytes, unspanned. Find the block accesses to fetch a record by key using (a) binary search on the data file sorted on the key, (b) a single-level primary index, (c) a single-level dense secondary index on another key field, (d) a multilevel index built on (c).

Solution
  1. , so .

  2. (a) , since .

  3. Index fan-out: .

  4. (b) Primary (sparse): (as ). Accesses .

  5. (c) Secondary (dense): (as ). Accesses .

  6. (d) Levels: 442, then , then 1, so and accesses . Without an index, a search on the non-ordering field reads blocks on average.

  7. A multilevel index on (b) has levels 45 and 1, so and 3 accesses.

Answer: (a) 12, (b) 7, (c) 10, (d) 4 block accesses.

B-trees and B+ trees

A B-tree or B+ tree is a balanced multiway search tree: every leaf is at the same depth, and nodes (except the root) are at least half full. Insertions split a full node and deletions merge or redistribute.

Conventions used here. The order of an internal node is its maximum number of child pointers (so at most keys). Height is the number of levels, counting the root as level 1 and the leaves as level . Minimum occupancy: a non-root internal node has at least children; the root has at least 2 children (if it is not a leaf); a leaf holding at most keys has at least keys. Some definitions state occupancy differently, so check the question.

EXAM TIP

Questions do not all define order the same way. Some mean the maximum number of keys in a node; others give a minimum degree , with every non-root node holding between and keys (so at most children). Convert to this page's (maximum child pointers) before using the formulas below.

Property

B-tree

B+ tree

Record pointers

In every node, beside each key

Only in the leaves

Keys in internal nodes

Each key appears once in the whole tree

Internal keys only guide the search; every key that has a record is in a leaf (after deletions a separator may no longer be in any leaf)

Leaves

Not linked

Linked in key order, so range scans follow the chain

Fan-out of internal nodes

Smaller (each key carries a record pointer)

Larger, so the tree is usually shallower

Every search ends

Possibly in an internal node

Always at a leaf, so all equality searches read the same number of levels

B+ TREE INTERNAL NODE ORDER

Largest satisfying this; internal nodes hold block pointers and keys.

B+ TREE LEAF CAPACITY

Largest number of keys in a leaf, where the extra is the next-leaf pointer.

B-TREE NODE ORDER

Each key in a B-tree node carries a record pointer, so one node type serves internal nodes and leaves.

KEYS STORED IN A B+ TREE OF HEIGHT H

Max: every node full, so leaves of keys. Min: the root has 2 children and every other internal node , giving leaves, each with keys.

KEYS STORED IN A B-TREE OF HEIGHT H

Max: all nodes full with keys each. Min: the root has 1 key (2 children) and every other node keys.

BLOCK ACCESSES FOR AN EQUALITY SEARCH

One block per level down to the leaf, plus one to read the data record. Leaves holding the record itself need only .

Range search on a B+ tree: accesses to reach the leaf holding , one more for each further leaf in the range (following the leaf chain), then, when leaves hold record pointers, up to one data-block access per matching record. It costs fewer if the file is also ordered on .

Splitting on insertion. When a B+ tree leaf already holding keys receives one more, it splits into two leaves of and keys (which half gets the extra key is a convention, so follow the question), and the smallest key of the new right leaf is copied up into the parent. When an internal node overflows, it splits and its middle key moves up: it stays in neither half. In a B-tree every split works like the internal-node split, with the middle key moving up. A split can propagate upward; when the root splits, a new root is created, and this is the only way the height grows.

WORKED EXAMPLE

A B+ tree index has block size bytes, key size bytes, block pointer bytes and record pointer bytes. Find the order of an internal node, the leaf capacity , and the maximum and minimum number of keys in a tree with levels. How many block accesses does an equality search take?

Solution
  1. Internal node: , so and .

  2. Leaf: , so and .

  3. Maximum keys: .

  4. Minimum: leaves ; keys per leaf ; total .

  5. Search: 3 index levels (root, internal, leaf) plus one data block gives 4 accesses.

Answer: , ; between 420 and 23,548 keys; 4 block accesses.

Hash-based indexing

Static hashing fixes buckets and sends a record with key to bucket (or another hash function). When a bucket is full, extra records go to overflow blocks chained to it, so a skewed or overloaded file degrades from about 1 access toward a chain scan.

Dynamic schemes avoid fixed size. In extendible hashing a directory of pointers is indexed by bits of the hash value, the first bits in some presentations and the last in others, so follow the question ( is the global depth). Each bucket has a local depth . When a bucket overflows, it splits and its local depth increases by 1; if the new local depth exceeds , the directory doubles. If all the bucket's records fall into the same half, the split repeats. Several directory entries may point to one bucket. Linear hashing instead splits buckets one at a time in a fixed order, with no directory.

EXTENDIBLE HASHING DIRECTORY

is the global depth and a bucket's local depth.

EXAM TIP

A hash index answers equality lookups in about one access, but it cannot answer range queries, prefix searches or ORDER BY efficiently, because hashing scatters neighbouring keys. A B+ tree handles all of these.

Choosing an index for a given query

Query shape

Useful index

Reason

WHERE a = c, one row expected

B+ tree or hash on a

Both reach the row in a few accesses; hash is about 1

WHERE a BETWEEN c1 AND c2

B+ tree on a (best if the file is also ordered on a, a clustering index)

Locate , then follow the leaf chain; hash cannot do this

WHERE a = c AND b = d

Index on a or b, or a composite index

A composite index lets one search satisfy both conditions

ORDER BY a

B+ tree on a

Leaves are already in key order (if the file is not ordered on a, fetching each row can cost one data access)

Condition on a function such as a+1 = c

Usually no index helps

The index is ordered on a, not on a+1

Condition matching a large fraction of rows (field with few distinct values)

Little benefit

The index leads to most blocks anyway, so a scan can be as good

EXAM TIP

A composite B+ tree index on helps queries that fix a (alone, or with b), but it cannot be used to search directly on b alone, because entries are sorted on a first. Also, an index speeds reads but costs extra block writes on every insert, delete and update of its field.

PREVIOUS-YEAR QUESTIONS

3 questions from the DA papers

Try each question first, then open the answer. We placed each question under a topic ourselves; the exam paper does not label topics.

See these papers in full: GATE DA 2026 · GATE DA 2024

GATE 2026 DA Q.32

GATE 2026 · DAQ.32 · 1 mark · NAT

In a relational database, a B+ Tree Index is to be constructed for a relation on a key field. In a B+ Tree, a Node Pointer points to a sub-tree and a Data Record Pointer points to a block of database records.

Let, Node size = 4096 bytes, Node Pointer size = 10 bytes, Search Key Field size = 11 bytes and Data Record Pointer size = 12 bytes.

The maximum number of Node Pointers that can be present in a non-leaf node of the B+ Tree is ________ . (Answer in integer)

Answer and solution
See the question in the paper
GATE 2026 DA Q.32: answer and solution

GATE 2026 DA Q.41

GATE 2026 · DAQ.41 · 2 marks · MCQ

Consider a B+ Tree where the maximum number of key values in each leaf node is 2 and the maximum number of pointers in each non-leaf node is 3. Let the content of the B+ Tree be as shown in the figure.

Which of the following options denotes the key value(s) stored in the root node after inserting a key value 3 in the given B+ Tree?

GATE 2026 DA question 41: A B+ tree.Tap to open full size
Figure from the GATE 2026 DA paper. It is part of the question.
Figure description

A B+ tree. The root (non-leaf) node holds keys 5 and 8 with three child pointers: left, middle and right. The left pointer goes to leaf [1, 5], the middle pointer to leaf [7, 8], the right pointer to leaf [9, 12]. The leaves are chained left to right by sibling pointers (the last leaf's next pointer is NULL). Each key in a leaf has a dashed downward arrow to its record. Following the figure, keys less than or equal to 5 are under the left pointer (leaf [1, 5] contains 5), keys from 6 to 8 under the middle pointer (leaf [7, 8]) and keys above 8 under the right pointer (leaf [9, 12]).

  1. (A)

    5

  2. (B)

    8

  3. (C)

    3 and 5

  4. (D)

    3, 5 and 8

Answer and solution
GATE 2026 DA Q.41: answer and solution

GATE 2024 DA Q.55

GATE 2024 · DAQ.55 · 2 marks · MSQ

An OTT company is maintaining a large disk-based relational database of different movies with the following schema:

Movie(ID, CustomerRating)
Genre(ID, Name)
Movie_Genre(MovieID, GenreID)

(Primary keys underlined in print: Movie.ID; Genre.ID; Movie_Genre.MovieID and GenreID together.)

Consider the following SQL query on the relation database above:

SELECT *
FROM Movie, Genre, Movie_Genre
WHERE
    Movie.CustomerRating > 3.4 AND
    Genre.Name = "Comedy" AND
    Movie_Genre.MovieID = Movie.ID AND
    Movie_Genre.GenreID = Genre.ID;

This SQL query can be sped up using which of the following indexing options?

  1. (A)

    B tree on all the attributes.

  2. (B)

    Hash index on Genre.Name and B tree on the remaining attributes.

  3. (C)

    Hash index on Movie.CustomerRating and B tree on the remaining attributes.

  4. (D)

    Hash index on all the attributes.

Answer and solution
See the question in the paper
GATE 2024 DA Q.55: answer and solution

PRACTICE

6 questions to test yourself

PRACTICE 11 mark · NAT

A file has 1000 fixed-length records of 300 bytes each, stored in disk blocks of 2048 bytes. Records are unspanned. How many data blocks does the file occupy?

Answer and solution

Answer:

  1. Blocking factor: , since and .

  2. Blocks: .

PRACTICE 22 marks · MSQ

Which of the following statements about single-level indexes on a data file are correct?

  1. (A)

    A sparse index requires the data file to be ordered on the indexed field.

  2. (B)

    The first level of a secondary index on a field by which the file is not ordered cannot be sparse.

  3. (C)

    A file can have two different clustering indexes, one on each of two different fields.

  4. (D)

    If the blocking factor is at least 2 and the file has at least two records, a sparse primary index on the ordering key field has fewer entries than a dense index on the same field.

Answer and solution

Answer: (A), (B), (D)

  1. A is correct: a sparse index relies on finding the block whose first key is at most the search key, which works only if records are in key order.

  2. B is correct: when the file is not ordered on the field, keys in a block are not related to the block's anchor, so every record (or every value) needs its own entry.

  3. C is false: the file can be physically ordered on only one field, so it has at most one primary or clustering index.

  4. D is correct: the sparse index has one entry per block, and when and , while the dense index has entries.

PRACTICE 32 marks · NAT

A B+ tree has internal nodes of order 10 (at most 10 child pointers and 9 keys) and leaves holding at most 9 keys. Non-root internal nodes have at least children, the root (not a leaf) has at least 2 children, and every leaf has at least keys. What is the minimum number of keys in such a tree that has exactly 3 levels (root, one level of internal nodes, leaves)?

Answer and solution

Answer:

  1. Minimum leaves: the root has 2 children, each internal node at level 2 has at least 5 children, so leaves.

  2. Minimum keys per leaf: .

  3. Minimum keys: (formula: ).

PRACTICE 42 marks · MCQ

A file has records and a dense multilevel secondary index on a key field. Each index entry is 16 bytes and each block is 4096 bytes. The top level of the index fits in one block. How many block accesses are needed to read one record by its key value, counting the data block?

  1. (A)

    3

  2. (B)

    4

  3. (C)

    5

  4. (D)

    20

Answer and solution

Answer: (B)

  1. Fan-out .

  2. First level (dense): blocks.

  3. Second level: blocks. Third level: block, so levels (check: ).

  4. Accesses (three index blocks plus the data block).

PRACTICE 51 mark · MCQ

A table Emp(id, dept, salary) has only a hash index on dept. Consider these queries.

Query P:

SELECT *
FROM Emp
WHERE dept = 'CS';

Query Q:

SELECT *
FROM Emp
WHERE dept > 'CS';

Query R:

SELECT *
FROM Emp
ORDER BY dept;

Query S:

SELECT *
FROM Emp
WHERE salary = 5000;

Which query can use this index effectively?

  1. (A)

    Query P

  2. (B)

    Query Q

  3. (C)

    Query R

  4. (D)

    Query S

Answer and solution

Answer: (A)

  1. A hash index maps an exact key value to its bucket, so an equality condition on dept (query P) is answered in about one access.

  2. Query Q is a range condition and query R needs key order; hashing scatters neighbouring keys, so neither benefits.

  3. Query S tests salary, which the index does not cover.

PRACTICE 61 mark · NAT

An extendible hash file has global depth 4. One of its buckets has local depth 2. How many directory entries point to this bucket?

Answer and solution

Answer:

  1. Entries pointing to a bucket .

OFFICIAL GATE 2027 SYLLABUS WORDING

Copied from the GATE 2027 syllabus; see all 2027 syllabi.

GATE DA

file organization, indexing

Preparing in Kolkata? IAE Academy's course for GATE DA.