### Resizing a hash table

• The need to grow a hash table

• Fact:

 The performance of a hash index depends on the number of overflows

Example:

• No overflows leads to good performance:

We need only read 1 disk block to find any search key

• Many overflows leads to poor performance:

 3 disk blocks

to find some search keys !!!!

• Recall:

• A hash function will map a search key to a value in the range [0 .. (B−1]:

• A typical hash function will be as follows:

 ``` Hash( key ) = random( key ) % B ```

Explanation:

 random(key) = a random integer number computed using the key value The modulo operator "% B" is used to map the integer random number to a value in the range [0 .. (B−1)]

• Dicdatical warning

• Warning:

• The value of B is always some prime number

(This spread the keys more uniformly over the range [0 .. (B−1)])

• However:

 For simplicity, in the following example, I will use: B = 10 (Because computing % 10 is easy)

• Accomodating more search keys

• Problem: changing the size of a hash table

• Suppose we use a hash table with size = 10

We use the following simple hash function:

 ``` Hash(x) = x%10 ```

Sample of the hash table content:

• Suppose we want to increase the hash table size to 20:

We must use a different hash function that covers the wider range !!!

For example:

 ``` Hash(x) = x % 20 ```

Result:

Consequence:

 We cannot find (some) the search keys stored in the hash table using the new hash function !!!

• Problem caused by changing the size of the hash table in ordinary hashing:

• Fact:

 Changing the size of the hash table require a change in the hash function

• Changing the hash function will result in:

 Unable to find the search keys that were stored previously in the hash table !!!

Solving the "can't find the search key" problem:

• We must re-map all the existing search keys using the new hash function and stored them in the new (size) hash table !!!

Example:

However:

 Re-mapping all existing search keys in a hash table is a very expensive operation !!!

• Dynamic Hashing: Techniques to change the size of a hash table

• We will discuss 2 "dynamic" hashing techniques where:

• The size of the hash table can increase (and decrease)

• When the size of hash table is changed:

 Only a fraction of the existing search keys need to be re-mapped !!!

• The dynamic hashing technqiues are:

• Extensible hashing:

 Extensible hashing can elminate the need/use of overflow block completely HoweverL the size of the hash table increases exponentially....

• Linear hashing:

 The size of the hash table increases linearly However: Linear hashing cannot elminate the need/use of overflow block