You are on page 1of 4

461 Tutorial Week 4 Lab 2

Rosa KarimiAdl

461 Tutorial Week 4 Lab 2

Hash Tables

Rosa KarimiAdl

14.3.5 In an extensible hash table with n records per block what is the probability that an overflowing
block will have to be handled recursively; i.e., all members of the block will go into the same one of the
two blocks created in the split?
Assume that we are currently considering j bits of hash value to determine membership in block B. Since
B is overflowing, it already has n records and we are trying to insert the n+1th record in it. Now we have
to split B and distribute records in B based on the value of their (j+1) st bit. If all of the n+1 records have
the same value for this bit, then they all go to one of the block and overflowing has to be handled
recursively. This probability is equal to:
1
1. All n+1 records have value 0 for the (j+1) st bit. (1/2)*(1/2)**(1/2) = ( )+1
2

1
2

2. Or All n+1 records have value 1 for the (j+1) st bit. (1/2)*(1/2)**(1/2) = ( )+1
1
2

1
2

1
2

The total would be: ( )+1 + ( )+1 = ( )

14.3.6 Suppose keys are hashed to four-bit sequences. Also suppose that blocks can hold three records.
If we start with a hash table with two empty blocks (corresponding to 0 and 1), show the organization
after we insert records with keys:
a) 0000,0001,. . . ,1111, and the method of hashing is extensible hashing.
Answer- When we insert 0011, there are four records for bucket 0, which overflows. Adding a second bit
to the bucket addresses doesn't help, because the first four records all begin with 00. Thus, we go to i =
3 and use the first three bits for each bucket address. Now, the records divide nicely, and by the time
1111 is inserted, we have two records in each bucket.
b) 0000,0001,. . . ,1111, and the method of hashing is linear hashing with a capacity threshold of 100%
We need to make sure that r 3 n all the time.

1|Page

461 Tutorial Week 4 Lab 2

2|Page

Rosa KarimiAdl

461 Tutorial Week 4 Lab 2

3|Page

Rosa KarimiAdl

461 Tutorial Week 4 Lab 2

Rosa KarimiAdl

14.3.7: Suppose we use a linear or extensible hashing scheme, but there are pointers to records from
outside. These pointers prevent us from moving records between blocks, as is sometimes required by
these hashing methods. Suggest several ways that we could modify the structure to allow pointers from
outside.
1. We could leave forwarding addresses in buckets when we split them.
2. We could use the full sequence of bits produced by the hash function as the pointer, and use the
extensible or linear hash table to look up a record whenever an external pointer was followed.

4|Page

You might also like