Indexing and Hashing # MCQs Practice set

Q.1 What is the main purpose of an index in a database?

To store extra copies of data
To improve query performance
To enforce data integrity
To back up the database
Explanation - An index helps in quickly locating data without scanning the entire table, thereby improving query performance.
Correct answer is: To improve query performance

Q.2 Which type of index stores the data itself in the index structure?

Secondary index
Clustering index
Non-clustering index
Hash index
Explanation - A clustering index determines the physical order of data in the table, so the index entries contain the actual data.
Correct answer is: Clustering index

Q.3 In hashing, what is the main role of the hash function?

To encrypt data
To map a key to a storage location
To sort the records
To create a backup
Explanation - The hash function takes a key and maps it to a specific location (bucket) in the storage for efficient access.
Correct answer is: To map a key to a storage location

Q.4 Which of the following is a disadvantage of using a dense index?

Slower search times
Consumes more storage space
Cannot be used for range queries
Requires sorted data
Explanation - A dense index contains an entry for every record, which consumes more storage compared to a sparse index.
Correct answer is: Consumes more storage space

Q.5 What type of hashing handles collisions by storing all collided records in a linked list?

Open addressing
Separate chaining
Double hashing
Linear probing
Explanation - Separate chaining resolves collisions by maintaining a linked list of all records that hash to the same location.
Correct answer is: Separate chaining

Q.6 Which of the following is true about primary indexes?

They are always dense
They are created on a primary key
They can contain duplicates
They use hashing
Explanation - Primary indexes are created on the primary key of a table, and usually correspond to a clustering index.
Correct answer is: They are created on a primary key

Q.7 In open addressing, what happens when a collision occurs?

The record is discarded
The record is placed in the next available location
The hash function is changed
The table is resized
Explanation - Open addressing resolves collisions by probing subsequent locations in the table until an empty spot is found.
Correct answer is: The record is placed in the next available location

Q.8 Which index type is best suited for range queries?

Hash index
B+ tree index
Bitmap index
Reverse index
Explanation - B+ tree indexes allow efficient traversal of records in order, making them ideal for range queries.
Correct answer is: B+ tree index

Q.9 What is a bucket in hashing?

A memory buffer
A storage location for records with the same hash value
A type of index
A database table
Explanation - A bucket is where all records that hash to the same value are stored, either in a linked list or a single location.
Correct answer is: A storage location for records with the same hash value

Q.10 Which of the following is an advantage of sparse indexes?

Faster insertion
Consumes less storage space
Supports range queries efficiently
Always dense
Explanation - Sparse indexes store fewer entries (one per block), which reduces storage usage compared to dense indexes.
Correct answer is: Consumes less storage space

Q.11 What does linear probing in hashing refer to?

Probing locations based on a random sequence
Probing consecutive locations until an empty spot is found
Probing using linked lists
Probing only the initial hash location
Explanation - Linear probing resolves collisions by checking the next sequential slots in the table until an empty one is located.
Correct answer is: Probing consecutive locations until an empty spot is found

Q.12 Which of the following indexing types is suitable for columns with low cardinality?

B+ tree index
Bitmap index
Hash index
Clustering index
Explanation - Bitmap indexes are efficient for columns with a small number of distinct values (low cardinality) because they use bitmaps for representation.
Correct answer is: Bitmap index

Q.13 What is the main disadvantage of open addressing compared to separate chaining?

It uses more memory
It may lead to clustering
It requires linked lists
It cannot handle collisions
Explanation - Open addressing can lead to primary clustering, where consecutive slots fill up, slowing down insertion and search operations.
Correct answer is: It may lead to clustering

Q.14 Which hashing technique uses two hash functions to resolve collisions?

Separate chaining
Linear probing
Double hashing
Quadratic probing
Explanation - Double hashing applies a second hash function to determine the next probe location when a collision occurs.
Correct answer is: Double hashing

Q.15 Which of the following is true about non-clustering indexes?

They determine the physical order of data
They store pointers to data records
They are always dense
They cannot be created on primary keys
Explanation - Non-clustering indexes maintain pointers to the actual data, rather than determining the physical order of the data itself.
Correct answer is: They store pointers to data records

Q.16 What is the worst-case search time for a hash table with separate chaining?

O(1)
O(log n)
O(n)
O(n log n)
Explanation - In the worst case, all keys may hash to the same bucket, resulting in a linked list of length n, giving O(n) search time.
Correct answer is: O(n)

Q.17 Which of the following is an example of static hashing?

Extendible hashing
Linear hashing
Hashing with fixed number of buckets
Dynamic hashing
Explanation - Static hashing uses a fixed number of buckets, unlike dynamic hashing which can expand or contract.
Correct answer is: Hashing with fixed number of buckets

Q.18 What is the height of a B+ tree with n keys if each node can contain at most m keys?

O(log n)
O(n)
O(m)
O(1)
Explanation - The height of a B+ tree grows logarithmically with the number of keys, assuming a branching factor of m.
Correct answer is: O(log n)

Q.19 Which of the following operations is slower in hash indexes compared to B+ trees?

Exact match search
Range queries
Insertions
Deletions
Explanation - Hash indexes are efficient for exact match searches but inefficient for range queries as the order of keys is not maintained.
Correct answer is: Range queries

Q.20 In extendible hashing, what is the purpose of the directory?

To store data records
To map hash values to buckets
To perform range queries
To prevent collisions
Explanation - The directory stores pointers to buckets and maps hash values to their corresponding buckets, allowing dynamic growth.
Correct answer is: To map hash values to buckets

Q.21 What happens when a bucket overflows in linear hashing?

The table shrinks
A new bucket is created, and some records are redistributed
The record is discarded
The hash function is ignored
Explanation - Linear hashing handles overflow by creating a new bucket and redistributing some existing records to maintain efficiency.
Correct answer is: A new bucket is created, and some records are redistributed

Q.22 Which index type is most suitable for high-cardinality columns?

Bitmap index
Hash index
B+ tree index
Sparse index
Explanation - B+ tree indexes are efficient for high-cardinality columns because they provide ordered traversal and efficient search.
Correct answer is: B+ tree index

Q.23 Which of the following is true about primary clustering in open addressing?

It reduces search time
It occurs when multiple keys hash to consecutive locations
It is used to store multiple hash functions
It prevents collisions
Explanation - Primary clustering happens when collisions cause consecutive locations to be filled, leading to longer probe sequences.
Correct answer is: It occurs when multiple keys hash to consecutive locations

Q.24 In database indexing, what is a candidate key usually associated with?

Bitmap index
Hash function
Unique index
Sparse index
Explanation - A candidate key often has a unique index created to enforce uniqueness and allow fast access.
Correct answer is: Unique index

Q.25 Which of the following is true about a dense index in a sorted file?

It has one entry per block
It has one entry per record
It is always unsorted
It cannot be used for range queries
Explanation - Dense indexes store an index entry for every record, facilitating direct access to individual records.
Correct answer is: It has one entry per record