CS FundamentalsHardProduct company interview · GATE level
A B+ tree index on a column is said to have a 'fan-out' of 100 (each internal node has up to 100 children). For a table with 10,000,000 rows, assuming a fully packed tree and leaves that each reference about 100 records, approximately how many levels (height) does the tree need, INCLUDING the leaf level?
- A. About 100 levels
- B. About 10,000,000 levels
- C. About 2 levels
- D. About 4 levels
Correct answer: D. About 4 levels
Leaves hold about 10,000,000 / 100 = 100,000 leaf entries worth of groups... more precisely: leaf level needs about 100,000 leaf nodes (10,000,000 records / 100 per leaf). Each level up reduces the node count by a factor of 100 (the fan-out): 100,000 → 1,000 → 10 → 1 (root). That is 4 levels above the records conceptually, i.e. about 4 levels total including the leaf level (leaf, then 3 levels of internal nodes up to the root) — consistent with the well-known rule that B+ trees stay very shallow (3-4 levels) even for huge tables.
More DBMS and SQL questions
- Which of these is the best reason a database might choose to use a bitmap index rather than a B+ tree index on a column?
- Two transactions, T1 and T2, both want to update the same row. T1 acquires a shared (read) lock, then later tries to upgrade to an…
- A query uses SELECT ... FOR UPDATE to explicitly lock the rows it reads within a transaction. What is the main purpose of this, compared…
- A long-running read-only transaction under snapshot isolation sees a consistent view of the database as of its start time, even while…
- A relation R(A, B, C) has the single functional dependency A → B (C is independent, with no FD at all involving it, and no candidate key…
- A table's clustered index key is UUID-based (a random 128-bit value) rather than a sequential integer. What problem does this commonly…