chapter

    File Organization, Indexing and B+ Trees Notes for Gate Cs

    File Organization, Indexing and B+ Trees notes for GATE CS: 27 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice questio

    File Organization Indexing and B Trees notes

    B+ Tree Insertion, Splitting and Occupancy

    Databases › File Organization, Indexing and B+ Trees

    B+ Tree Mechanics

    Mastering insertion, splitting, and balance.

    What you will learn here
    1
    The step-by-step algorithm for inserting keys into leaf and internal nodes.
    2
    How node splitting works and how the middle key propagates upward.
    3
    Occupancy constraints: why nodes must be at least half full.

    B+ Tree Structure and Order

    B+ Tree Structure and Order

    1. The Order ()

    Defines node capacity. A node has at most child pointers and keys. Note: Verify if the problem specifies "max keys" or "max pointers".

    2. Balanced Property

    All leaf nodes are at the same depth. This guarantees consistent search time for any key.

    3. Leaf vs Internal Nodes

    Internal Nodes: Contain keys and child pointers. Act as an index.

    Leaf Nodes: Contain keys and data pointers. Linked for range queries.

    Key Insight: Because internal nodes do not store data pointers, they can hold more keys per block, reducing the tree height.

    Insertion Algorithm: Leaf Node Overflow

    Insertion: Leaf Node Overflow

    1

    Find Leaf

    Traverse the tree to find the appropriate leaf node .

    2

    Check Space

    If has keys, insert in sorted order. If full ( keys), Overflow.

    3

    Split Leaf

    Temporarily include new key in (now keys). Sort all keys.

    Left Node
    First keys
    Right Node
    Remaining keys

    Separator: Smallest key of Right Node is copied to parent.

    Crucial Rule: In B+ Trees, the separator key is copied to the parent, not moved. It remains in the leaf.

    Visualizing Leaf Split
    [10]
    [15, 20]
    15

    24 more cards in this chapter

    Try a question

    Answer it here to see how it works. Nothing is recorded until you sign in.

    Question 1
    Level 1: Warm-up

    In a B+ tree, when an internal node splits due to overflow, what happens to the median key?

    Question 2
    Level 1: Warm-up

    Which of the following conditions strictly bounds the height increase in a B+ tree during a single insertion?

    Question 3
    Level 1: Warm-up

    Consider the following statements regarding database indexing:

    Statement 1: A secondary index must always be a dense index.

    Statement 2: A primary index must always be a sparse index.

    Which of the following options is correct?

    Question 4
    Level 1: Warm-up

    Consider the following statements about database indexes:

    Statement 1: A primary index typically has lower storage overhead than a secondary index.

    Statement 2: A secondary index is built on the ordering key field of the data file.

    Which of the following options is correct?

    Question 5
    Level 1: Warm-up

    A data file contains $10,000$ records distributed across $500$ blocks. The file is unordered. An index is built on a non-ordering candidate key. If each index entry requires $20$ bytes and the block size is $4,000$ bytes, what is the exact number of blocks required for this index?

    Question 6
    Level 1: Warm-up

    Consider the following statements regarding database indexes:

    S1: If a data file is physically unordered, any index built on it must contain at least one entry per data record.

    S2: If a data file is physically ordered by a key, an index on that key must contain exactly one entry per data block.

    Which of the following options is correct?

    Question 7
    Level 1: Warm-up

    Consider the following statements regarding database indexes:

    Which of the statements are correct?

    Question 8
    Level 1: Warm-up

    A data file contains $12,000$ records distributed across $500$ blocks. The file is unordered. A secondary index is built on a candidate key. If each index entry requires $20$ bytes and the block size is $4096$ bytes, what is the minimum number of blocks required to store the leaf level of this index?

    Question 9
    Level 1: Warm-up

    A data file contains $10,000$ records distributed across $400$ blocks. The file is unordered. A secondary index is built on a candidate key. Each index entry requires $20$ bytes, and the block size is $1,000$ bytes. Which of the following statements about the index are correct?

    Question 10
    Level 1: Warm-up

    A data file contains $9,000$ records distributed across $300$ blocks. The file is unordered. A secondary index is built on a candidate key. Each index entry requires $20$ bytes, and the block size is $1,000$ bytes. What is the minimum number of blocks required to store the leaf level of this index?

    Free preview ends here

    Login to view the complete notes

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Explore complete test series, official past papers, and chapter-wise study tools.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    File Organization, Indexing and B+ Trees Notes for GATE CS

    File Organization, Indexing and B+ Trees notes for GATE CS: 27 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice questions.

    B+ Tree Insertion, Splitting and Occupancy

    Databases › File Organization, Indexing and B+ Trees

    B+ Tree Mechanics

    Mastering insertion, splitting, and balance.

    What you will learn here
    1
    The step-by-step algorithm for inserting keys into leaf and internal nodes.
    2
    How node splitting works and how the middle key propagates upward.
    3
    Occupancy constraints: why nodes must be at least half full.

    B+ Tree Structure and Order

    B+ Tree Structure and Order

    1. The Order ()

    Defines node capacity. A node has at most child pointers and keys. Note: Verify if the problem specifies "max keys" or "max pointers".

    2. Balanced Property

    All leaf nodes are at the same depth. This guarantees consistent search time for any key.

    3. Leaf vs Internal Nodes

    Internal Nodes: Contain keys and child pointers. Act as an index.

    Leaf Nodes: Contain keys and data pointers. Linked for range queries.

    Key Insight: Because internal nodes do not store data pointers, they can hold more keys per block, reducing the tree height.

    Insertion Algorithm: Leaf Node Overflow

    Insertion: Leaf Node Overflow

    1

    Find Leaf

    Traverse the tree to find the appropriate leaf node .

    2

    Check Space

    If has keys, insert in sorted order. If full ( keys), Overflow.

    3

    Split Leaf

    Temporarily include new key in (now keys). Sort all keys.

    Left Node
    First keys
    Right Node
    Remaining keys

    Separator: Smallest key of Right Node is copied to parent.

    Crucial Rule: In B+ Trees, the separator key is copied to the parent, not moved. It remains in the leaf.

    Visualizing Leaf Split
    [10]
    [15, 20]
    15

    Worked Example: Leaf Split

    Worked Example: Leaf Split

    Given

    Order: (Max 2 keys)
    Leaf :
    Insert: $15$

    Process

    1
    Overflow: is full. Add 15 temporarily: .
    2
    Split: Left gets key . Right gets $2$ keys .
    3
    Update Parent: Copy $15$ to parent.

    Result

    Parent:
    Left Leaf:
    Right Leaf:

    File Organization, Indexing and B+ Trees: Solved Questions with Step-by-Step Explanations (10 Problems)

    Question 1 · Databases MCQ

    In a B+ tree, when an internal node splits due to overflow, what happens to the median key?

    1. A.

      It is copied to the parent and remains in the internal node

    2. B.

      It is deleted from the tree

    3. C.

      It is moved to the parent and removed from the internal node

    4. D.

      It is copied to both the parent and the sibling node

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: This tests the critical difference between leaf splits and internal node splits. In a B+ tree: - Leaf split: The separator key is copied to the parent and remains in the right leaf - Internal node split: The median key is moved to the parent and removed from the current node This difference exists because internal nodes don't store data — they only guide searches. The median key must move up to maintain the search structure. Answer: It is moved to the parent and removed from the internal node
    Question 2 · Databases MCQ

    Which of the following conditions strictly bounds the height increase in a B+ tree during a single insertion?

    1. A.

      The height increases by 1 only if the root node splits.

    2. B.

      The height increases by 1 for every internal node that splits.

    3. C.

      The height increases by 1 only if a leaf node splits.

    4. D.

      The height never increases by more than 2 during a single insertion.

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: This is a bounding question testing the specific condition for height increase in B+ trees.

    In a B+ tree, splits can propagate from the leaf up to the root. However, the height of the tree only increases when the root node itself splits, creating a new root.

    Step 1: Leaf splits do not increase height.

    Step 2: Internal node splits do not increase height.

    Step 3: Only a root split increases the height by exactly 1.

    Answer: The height increases by 1 only if the root node splits.

    Question 3 · Databases MCQ

    Consider the following statements regarding database indexing:

    Statement 1: A secondary index must always be a dense index.

    Statement 2: A primary index must always be a sparse index.

    Which of the following options is correct?

    1. A.

      Both Statement 1 and Statement 2 are true

    2. B.

      Statement 1 is true but Statement 2 is false

    3. C.

      Statement 1 is false but Statement 2 is true

    4. D.

      Both Statement 1 and Statement 2 are false

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This is a bounding question testing the strict rules of index density for primary and secondary indexes.

    A secondary index is built on a non-ordering field, meaning records are scattered. Therefore, it must be dense to guarantee every record can be found. A primary index is built on an ordering field, so it can be sparse, but it is not strictly required to be sparse (it can be dense).

    Step 1: Evaluate Statement 1. Secondary indexes must always be dense. This is TRUE.

    Step 2: Evaluate Statement 2. Primary indexes must always be sparse. This is FALSE (they are typically sparse, but can be dense).

    Answer: Statement 1 is true but Statement 2 is false

    Question 4 · Databases MCQ

    Consider the following statements about database indexes:

    Statement 1: A primary index typically has lower storage overhead than a secondary index.

    Statement 2: A secondary index is built on the ordering key field of the data file.

    Which of the following options is correct?

    1. A.

      Both statements are true

    2. B.

      Statement 1 is true but Statement 2 is false

    3. C.

      Statement 1 is false but Statement 2 is true

    4. D.

      Both statements are false

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This is a bounding question testing the structural differences between primary and secondary indexes.

    A primary index is built on the ordering key and is typically sparse, meaning fewer entries and lower storage overhead. A secondary index is built on a non-ordering field and must be dense, meaning more entries and higher storage overhead.

    Step 1: Evaluate Statement 1. Primary index has lower storage overhead. This is TRUE (because it is typically sparse).

    Step 2: Evaluate Statement 2. Secondary index is built on the ordering key. This is FALSE (it is built on a non-ordering field).

    Answer: Statement 1 is true but Statement 2 is false

    Question 5 · Databases MCQ

    A data file contains $10,000$ records distributed across $500$ blocks. The file is unordered. An index is built on a non-ordering candidate key. If each index entry requires $20$ bytes and the block size is $4,000$ bytes, what is the exact number of blocks required for this index?

    1. A.

      3

    2. B.

      50

    3. C.

      200

    4. D.

      500

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This is a boundary condition question testing whether you recognize that an index on a non-ordering key of an unordered file must be dense.

    Why it applies: The question specifies "unordered" and "non-ordering candidate key", which triggers the strict rule that the index must be dense (one entry per record).

    Step 1: Determine index density. Since the file is unordered and the key is non-ordering, the index must be dense.

    Total entries = Total records = $10,000$.

    Step 2: Calculate the blocking factor for the index ($bfr$).

    $bfr = \lfloor \text{Block Size} / \text{Entry Size} \rfloor = \lfloor 4000 / 20 \rfloor = 200$ entries/block.

    Step 3: Calculate the number of index blocks.

    $\text{Blocks} = \lceil \text{Total Entries} / bfr \rceil = \lceil 10000 / 200 \rceil = 50$.

    Answer: B

    Common trap: Students often miss the "unordered/non-ordering" condition and assume the index can be sparse. If they use sparse, they calculate entries = 500 blocks, leading to $\lceil 500 / 200 \rceil = 3$ blocks (Option A).

    Question 6 · Databases MCQ

    Consider the following statements regarding database indexes:

    S1: If a data file is physically unordered, any index built on it must contain at least one entry per data record.

    S2: If a data file is physically ordered by a key, an index on that key must contain exactly one entry per data block.

    Which of the following options is correct?

    1. A.

      S1 only

    2. B.

      S2 only

    3. C.

      Both S1 and S2

    4. D.

      Neither S1 nor S2

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: This is a statement truth question testing the strict constraints on index density based on file organization.

    Step 1: Analyze S1.

    "If a data file is physically unordered, any index built on it must contain at least one entry per data record."

    An unordered file is a heap file. Any index on a heap file is a secondary index. Because the file is not sorted, records with the same key can be scattered anywhere. To guarantee every record can be found, the index must be dense (one entry per record).

    Therefore, S1 is TRUE.

    Step 2: Analyze S2.

    "If a data file is physically ordered by a key, an index on that key must contain exactly one entry per data block."

    An index on the ordering key of an ordered file is a primary index. A primary index CAN be sparse (one entry per block), but it doesn't HAVE to be. It could also be implemented as a dense index. The word "must" makes this statement false.

    Therefore, S2 is FALSE.

    Answer: S1 only

    Question 7 · Databases MSQ

    Consider the following statements regarding database indexes:

    Which of the statements are correct?

    1. A.

      If a data file is a heap file, any index built on it must be dense.

    2. B.

      A primary index can be implemented as either dense or sparse.

    3. C.

      A secondary index can be implemented as a sparse index to save storage space.

    4. D.

      An index on a non-ordering field of an ordered file must be dense.

    Correct Answer:

    ["A","B","D"]

    Step-by-Step Solution

    Key idea: This is a statement truth question testing the strict constraints on index density based on file organization.

    Step 1: Analyze statement A.

    A heap file is unordered. Any index on a heap file is a secondary index. Because the file is not sorted, records with the same key can be scattered anywhere. To guarantee every record can be found, the index must be dense.

    Therefore, A is TRUE.

    Step 2: Analyze statement B.

    A primary index is built on the ordering key of an ordered file. While it is typically implemented as sparse to save space, it CAN also be implemented as dense. There is no strict rule forcing it to be sparse.

    Therefore, B is TRUE.

    Step 3: Analyze statement C.

    A secondary index is built on a non-ordering field. Because the file is not sorted by this field, you cannot predict where a record lies. You must have an explicit pointer for every single record. Therefore, a secondary index MUST be dense; it cannot be sparse.

    Therefore, C is FALSE.

    Step 4: Analyze statement D.

    An index on a non-ordering field of an ordered file is still a secondary index (because the file is not sorted by THIS specific field). As established, secondary indexes must be dense.

    Therefore, D is TRUE.

    Answer: A, B, D

    Question 8 · Databases MCQ

    A data file contains $12,000$ records distributed across $500$ blocks. The file is unordered. A secondary index is built on a candidate key. If each index entry requires $20$ bytes and the block size is $4096$ bytes, what is the minimum number of blocks required to store the leaf level of this index?

    1. A.

      58

    2. B.

      59

    3. C.

      60

    4. D.

      3

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: This is a direct formula application question. We must first determine the type of index (dense or sparse) based on the file organization, then calculate the index blocking factor and total blocks.

    Step 1: Determine index density.

    The data file is unordered, and the index is on a candidate key. This makes it a secondary index. A secondary index on an unordered file must always be a dense index.

    Therefore, the number of index entries = number of data records = $12,000$.

    Step 2: Calculate the index blocking factor ($bfr_i$).

    $bfr_i = \lfloor \text{Block size} / \text{Index entry size} \rfloor = \lfloor 4096 / 20 \rfloor = 204 \text{ entries/block}$.

    Step 3: Calculate the number of blocks for the leaf level.

    $\text{Blocks} = \lceil \text{Total entries} / bfr_i \rceil = \lceil 12000 / 204 \rceil = \lceil 58.82 \rceil = 59 \text{ blocks}$.

    Answer: 59

    Question 9 · Databases MSQ

    A data file contains $10,000$ records distributed across $400$ blocks. The file is unordered. A secondary index is built on a candidate key. Each index entry requires $20$ bytes, and the block size is $1,000$ bytes. Which of the following statements about the index are correct?

    1. A.

      The index must be dense.

    2. B.

      The total number of index entries at the leaf level is 10,000.

    3. C.

      The minimum number of blocks required for the leaf level is 200.

    4. D.

      The minimum number of blocks required for the leaf level is 8.

    Correct Answer:

    ["A","B","C"]

    Step-by-Step Solution

    Key idea: This is a direct formula application question. We must determine the index type (dense or sparse) based on the file organization, then calculate the index blocking factor and total blocks.

    Step 1: Determine index density.

    The data file is unordered, and the index is on a candidate key. This makes it a secondary index. A secondary index on an unordered file must always be a dense index.

    Therefore, the number of index entries = number of data records = $10,000$.

    Step 2: Calculate the index blocking factor ($bfr_i$).

    $bfr_i = \lfloor \text{Block size} / \text{Index entry size} \rfloor = \lfloor 1000 / 20 \rfloor = 50 \text{ entries/block}$.

    Step 3: Calculate the number of blocks for the leaf level.

    $\text{Blocks} = \lceil \text{Total entries} / bfr_i \rceil = \lceil 10000 / 50 \rceil = 200 \text{ blocks}$.

    Answer: A, B, C

    Question 10 · Databases NAT

    A data file contains $9,000$ records distributed across $300$ blocks. The file is unordered. A secondary index is built on a candidate key. Each index entry requires $20$ bytes, and the block size is $1,000$ bytes. What is the minimum number of blocks required to store the leaf level of this index?

    Correct Answer:

    180.00

    Step-by-Step Solution

    Key idea: This is a direct formula application question. We must determine the index type (dense or sparse) based on the file organization, then calculate the index blocking factor and total blocks.

    Step 1: Determine index density.

    The data file is unordered, and the index is on a candidate key. This makes it a secondary index. A secondary index on an unordered file must always be a dense index.

    Therefore, the number of index entries = number of data records = $9,000$.

    Step 2: Calculate the index blocking factor ($bfr_i$).

    $bfr_i = \lfloor \text{Block size} / \text{Index entry size} \rfloor = \lfloor 1000 / 20 \rfloor = 50 \text{ entries/block}$

    Step 3: Calculate the number of blocks for the leaf level.

    $\text{Blocks} = \lceil \text{Total entries} / bfr_i \rceil = \lceil 9000 / 50 \rceil = 180 \text{ blocks}$

    Answer: 180.00

    More notes in this unit