CSE370 - Indexing and Hashing (Practice Sheet)
CSE370 - Indexing and Hashing (Practice Sheet)
Practice Sheet
Indexing and Hashing
Question 1:
An EMPLOYEE file with ID# as the key field includes records with the following ID# values: 8, 5, 1, 7,
3, 12, 9, 6. Suppose that the search field values are inserted in the given order in a B+-tree of order n = 3;
show how the tree will expand and what the final tree will look like.
Question 2:
An EMPLOYEE file with ID# as the key field includes records with the following ID# values: 8, 5, 1, 7,
3, 12, 9, 6. Suppose that the search field values are inserted in the given order in a B+-tree of order n = 4;
show how the tree will expand and what the final tree will look like.
Question 3:
A. An EMPLOYEE file with ID# as the key field includes records with the following ID# values:
15, 5, 20, 10, 65, 55, 60, 50, 30, 25, 35, 90, 85, 95, 105, 100, 110, 115. Suppose that the search
field values are inserted in the given order in a B+-tree of order n = 4; show how the tree will
expand and what the final tree will look like.
B. After building the tree in this sequence, describe in your words how you will search for these
values in the tree: 65 and 120.
Question 4:
Question 5:
Suppose you have a table titled ‘“Instructor”.
A. Make a hash index on attribute instructor_id. Suppose the number of buckets in the hash
index is 5 and each bucket can house 2 index entries at max. Bucket overflow is handled
using forward chaining.
B. Explain how to search for the following search keys in your hash index.
● 45565
● 11113
Question 6:
Suppose you have a table titled ‘“Instructor”.
Make a hash index on attribute instructor_name (2nd column). Suppose the number of buckets
in the hash index is 5 and each bucket can house 3 index entries at max. Bucket overflow is
handled using forward chaining. The values of each character from A-Z (or a-z) is 1-26
respectively
Question 7:
Suppose you have the table below for “Instructors” for a School Database with columns ID,
Name, Subject and Salary respectively:
Suppose the number of buckets in the hash index is 5 and each bucket can hold 3 index entries at max.
Construct a hash index on attribute ID. Bucket overflow is handled using forward chaining. The hash
function, h = (First digit of ID) % 5.
Now let's assume there is another hash function, h = (Last digit of ID) % 5.
SOLUTIONS:
Answer 1:
Answer 2:
Answer 3:
A.
B. Searching 65:
Start at root with values 55, 100. 65 is RHS of 55 which has values 65 and 90, so go to RHS of 65
and we reach the leaf, the first value is 65.
Searching 120:
Start at root with values 55, 100. 120 is RHS of 100, where the node value is 110. 120 is again in
the RHS of node 110, we reach the leaf node. The values are 110 and 115, so 120 does not exist.
Answer 4:
Take help from slides, books and online materials to write a concise answer to each question in your own
words.
Answer5:
A.
B:
h(11113) = 2
Therefore, we examine the buckets located at index 2. Upon retrieving the initial bucket, two
records, namely 12121 and 76766, are obtained. Subsequently, retrieving the second bucket
yields the entry 83821. At this point, all buckets at index 2 have been retrieved, and the end of
the linked list has been reached. Consequently, the search for the key 11113 concludes without
success.
Answer 7:
The 1st hash function is more uniform compared to the later one. As no buckets were empty in the 1st
case. However, in the 2nd case not only were there empty buckets but also there was an overflow in the
bucket.