Skip to content
Official PYQ · 2011

GATE CS 2011 Q39 — File Organization and Indexing (B and B+ Trees)

Explain with AI

Consider a relational table rr with sufficient number of records, having attributes A1,A2,…,AnA_1, A_2, \dots ,A_n and let 1≤p≤n1 \leq p \leq n. Two queries Q1Q1 and Q2Q2 are given below.

  • Q1:πA1,…,Ap(σAp=c(r))Q1: \pi_{A_1, \dots ,A_p} \left(\sigma_{A_p=c}\left(r\right)\right) where cc is a constant
  • Q2:πA1,…,Ap(σc1≤Ap≤c2(r))Q2: \pi_{A_1, \dots ,A_p} \left(\sigma_{c_1 \leq A_p \leq c_2}\left(r\right)\right) where c1c_1 and c2c_2 are constants.

The database can be configured to do ordered indexing on ApA_p or hashing on ApA_p. Which of the following statements is TRUE?

Choose one option
View worked solution

Answer: C

To determine which indexing technique is better suited for each query, let's analyze how Hashing and Ordered Indexing handle equality and range searches:

  1. Query Q1Q1 (Equality Search): πA1,…,Ap(σAp=c(r))\pi_{A_1, \dots ,A_p} \left(\sigma_{A_p=c}\left(r\right)\right) This query searches for records where the attribute ApA_p is exactly equal to a constant cc.
    • Hashing: A hash index uses a hash function to map the search key directly to its bucket, requiring O(1)O(1) average-case disk I/O operations.
    • Ordered Indexing (e.g., B+ Tree): Finding a specific key requires traversing the tree from the root to a leaf, which takes O(log⁡N)O(\log N) disk I/O operations.
    • Conclusion: Hashing outperforms ordered indexing for equality queries like Q1Q1.

  2. Query Q2Q2 (Range Search): πA1,…,Ap(σc1≤Ap≤c2(r))\pi_{A_1, \dots ,A_p} \left(\sigma_{c_1 \leq A_p \leq c_2}\left(r\right)\right) This query retrieves records where the attribute ApA_p falls within a range [c1,c2][c_1, c_2].
    • Hashing: Hash functions do not preserve the ordering of keys. To answer a range query, hashing cannot easily locate the range boundaries, often requiring a full scan of the index or table.
    • Ordered Indexing: Since the keys are stored in sorted order, we can locate the starting point c1c_1 in O(log⁡N)O(\log N) time and then sequentially traverse the leaf nodes to retrieve all records up to c2c_2.
    • Conclusion: Ordered indexing outperforms hashing for range queries like Q2Q2.

Thus, hashing will outperform ordered indexing on Q1Q1, but not on Q2Q2.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore File Organization and Indexing (B and B+ Trees) questions