0% found this document useful (0 votes)
8 views63 pages

HASHING

The document provides an overview of hashing, including its definition, the structure of hash tables, and the role of hash functions. It discusses various types of hash functions and collision resolution techniques, such as chaining and open addressing. Additionally, it highlights the challenges associated with collisions and the characteristics of effective hash functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views63 pages

HASHING

The document provides an overview of hashing, including its definition, the structure of hash tables, and the role of hash functions. It discusses various types of hash functions and collision resolution techniques, such as chaining and open addressing. Additionally, it highlights the challenges associated with collisions and the characteristics of effective hash functions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 63

UNIT-II

Hashing

Dr.SK. YAKOOB
Associate Professor & HOD
INTRODUCTION TO HASHING
• Hashing is a technique to convert a range of key values
into a range of indexes of an array.
• Every value contains unique key.
• To access the values, use keys.
• It is a effective way to insert or retrieve data
• Hashing can be done with the help of
– Hash Table
– Hash Function
HASH TABLE
• Hash table is a data structure used for storing and
retrieving data very quickly.
• Insertion of data in the hash table is based on the key
value. Hence every entry in the hash table is associated
with some key.
• These key values are created by the hash function
Key Data
0 150
1 250
HASH FUNCTION
• Hash function is a mathematical expression.
• It produces a key for hash table elements .
• The integer returned by the hash function is called hash key.
• The main aim is to distribute the elements randomly.
• We can use the same hash function to put/retrieve the data
in/from the hash table.
• Example: If the key is 496700 it can be stored at 0th position. The second key
8421002, the record of those key is placed at 2nd position in the array.
Hence the hash function will be- H(key) = key%1000 Where key%1000 is a hash
function and key obtained by hash function is called hash key.
• Bucket and Home bucket: The hash function H(key) is used to
map several dictionary entries in the hash table. Each position of the
hash table is called bucket.
TYPES OF HASH FUNCTION
• 1. Division Method
• 2. Mid-Square Method
• 3. Multiplicative Method
• 4. Digit Folding
• 5. Digit Analysis
1. Division Method
• Simplest Method of Hashing.
• It depends upon the remainder of the division. Typically the
divisor is table length. Ke Data
y
• Hash Function is
0
• H(Key)=Record% Table Size. 1 21
• Example: 2
– Hash Function  H(Key)= X % 10 3 43
4
– Insert 55,43,21,67 5 55
6
– H(55)= 55%10  5 7 67
– H(43)= 43%10  3 8
– H(21)= 21%10  1 9
– Hash Table.
H(67)= 67%10  7
2. Mid- Square Method
• It is two steps hashing function.
• In this method, the key is squared and the middle or mid
part of the result is used as the index.
• If the key is a string, it has to be pre-processed to produce a
number. Ke Data
y
• Example:
0
– 3111  31112= 9678321
1
Hash Table. 2
– For the hash table of size 10
3
4
– H(3111)= 8 (The middle one Digit)
5
6
7
3. Multiplicative Hash Function
• This Function creates a key with five steps.
– Step1: Choose a constant A such that 0<A<1
– Step2: Multiply the key K with A
– Step3: Extract the factorial part of KA
– Step4: Multiply the result of Step3 with the size of the hash table n.
– Step5: Take the floor value of Step4 result.
• Donald Knuth Morris suggested choice for A is 0.6180339887
– H(k)= floor(n(factorial(kA)))%tablesize;

– For the key=107 and n=50 then

– H(107)= floor(50*(factorial(107*0.6180339887)))%50
– = (3306.4818458045)%50
– = 06 is the location in the hash table for storing record 107
4. Digit Folding Method
• This method creates a key with two steps.
– Step1: Divide the key into multiple parts, each part size based on your desired
key size. If your key contains three digits then each part maximum size is three
digits.
– Step2: Add all individual parts obtained in step1 ,ignore if any extra digits.

Ke Data
• Example: y
– Key =123456 10 123456
11
– Step1: Key parts  12,34,56 of key size is two digits Hash Table. 12
13
– Step2: sum= 12+34+56  102  key is 10 ,two digits 14
15
16
17
5. Digit Analysis Method
• The digit analysis is used in a situation when all the
identifiers are known in advance
• We first transform the identifiers into numbers using some radix, r.
• Then examine the digits of each identifier. Some digits having most
skewed distributions are deleted.
• This deleting of digits is continued until the number of remaining digits
is small enough to give an address in the range of the hash table.
• Here we make a statistical analysis of digits of the key and select
those digits which occur quite frequently.
• Then reverse or shifts the digits to get the address
– Eg: the key is 986126324
– If the statistical analysis revealed that third and fifth position digits occur
frequently
– We choose 6 and 2 , we get 62 and reverse it then we get 26 as address
Collision
• The hash function is a function that returns the key value using which
the record can be placed in the hash table.
• The situation in which the hash function returns the same hash key
(home bucket) for more than one record is called collision and two
same hash keys returned for different records is called synonym.
• Similarly when there is no room for a new pair in the hash table then
such a situation is called overflow. Key Data
0
• Example:
1 21
– Consider Hash Function  H(key)=Record%10
2
– Insert 25  25%10  5 3
– Insert 21  21%10  1 4
– Insert 36  36%10  6 5 25
– Now insert 45  45%10  5 Collision occurs 6 36
7
8
9
Collision
• Collision occurs when the hash function maps two different keys to
the same location.
• Two records cannot be stored in same place.
• Collisions can be reduced by good hash function
• Good hash function characteristics.
– Simple to compute
– No. of Collisions should be less.
– Hash function should depend on every bit of they key
– It should produce keys and distribute uninformly over an array.
• Good hash function also cannot avoid collisions.
• We use some techniques to solve hash table collision problem
• These Techniques are called Collision Resolution Techniques.
Collision Resolution Techniques
• 1. Chaining
• 2. Open Addressing
– Linear Probing
– Quadratic Probing
– Double Hashing
• 3. Rehashing
• 4. Extendible Hashing
1. Chaining
• It introduces an additional data field i.e Chain
• A separate chain table(linked list) is maintained for colliding data.
• When collision occurs then a linked list(chain) is maintained at the
home bucket.
Key Data
0 ADDRESS KEY NEXT KEY NULL
1 NULL
2 ADDRESS KEY NULL
3 NULL
4 ADDRESS KEY NEXT KEY NULL
5 NULL
6 NULL
7 ADDRESS KEY NEXT KEY NEXT KEY NULL
8 NULL
9 NULL
Collision
• Example:
– Consider Hash Function  H(key)=Record%10 Key Data
0

– Insert 25  25%10  5 1 21
2
3
– Insert 21  21%10  1
4
5 25
– Insert 36  36%10  6
6 36
7
– Now insert 45  45%10  5 8
9
• Collision occurs
1. Chaining
• Example
– Consider Hash Function  H(key)=Record
%10
Key Data
0 NULL
– Insert 25  25%10  5
1 ADDRES 21 NULL
S
– Insert 21  21%10  1 2 NULL
3 NULL
– Insert 36  36%10  6 4 NULL 25 NEXT 45 NULL
5 ADDRES
S 36 NEXT
– Now insert 45  45%10  5 6 ADDRES
S
7 NULL
8 NULL
9 NULL
Disadvantages
• Need more space as we are storing the address of next element.

• Searching a element may become difficult if the chain is long.

• Sometimes space will be wasted.


2. Open Addressing
• It is also called as closed hashing
• All keys sorted inside the hash table
• If collision occurs this method search for the alternative empty
location.
• This searching is called as Probing.
Key Data
0 20
• Hash Function H(x)=x%10 1 NULL
2 22
3 NULL
• Insert 107 4 NULL
5 NULL
– H(107)=107%10  7 6 NULL
7 87
8 NULL
9 NULL
2. Open Addressing
• It is also called as closed hashing
• All keys sorted inside the hash table
• If collision occurs this method search for the alternative empty
location.
• This searching is called as Probing.
Key Data
0 20
• Hash Function H(x)=x%10 1 NULL
2 22
3 NULL
• Insert 107 4 NULL
5 NULL
– H(107)=107%10  7 6 NULL
7 87
8 107
9 NULL
2. Open Addressing Types
• Linear Probing
• Quadratic Probing
• Double Hashing
Linear Probing
• In this technique if a value is already available at the desire
key in the hash table then new key will be created.
• New key will be created with the function
– H(k,i)=[H’(k)+i] mod n
Key Data
0 20
– Where 1 NULL
– H’(k) Generated key by hash function 2 22
– i  Probe number(0<=i<=n) 3 NULL
– n  Size of the hash table 4 NULL
– H(k,i)  New key after probing 5 NULL
6 NULL
7 87
8 107
9 NULL
Linear Probing
 H(k,i)=[H’(k)+i] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 NULL
i=1, n=10 2 NULL
3 NULL
 Insert 95 4 NULL
5 NULL
6 NULL
Hash Function  H’(95) = 95 % 10
7 NULL
5
8 NULL
9 NULL
Linear Probing
 H(k,i)=[H’(k)+i] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 NULL
i=1, n=10 2 NULL
3 NULL
 Insert 95 4 NULL
5 95
6 NULL
Hash Function  H’(95) = 95 % 10
7 NULL
5
8 NULL
 Insert 21 9 NULL

Hash Function  H’(21) = 21 % 10


1
Linear Probing
 H(k,i)=[H’(k)+i] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 21
i=1, n=10 2 NULL
3 NULL
Insert 95 4 NULL
 Hash Function  H’(95) = 95 % 5 95
10 6 NULL

5 7 NULL
Insert 21 8 NULL
 Hash Function  H’(21) = 21 % 9 NULL
10
1
Insert 41
 Hash Function  H’(41) = 41 %
10
Linear Probing
 H(k,i)=[H’(k)+i] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 21
i=1, n=10,k=41 2 NULL
3 NULL
Insert 41
4 NULL
 Hash Function  H’(41) = 41 % 5 95
10 6 NULL
1 7 NULL
Generate new key: 8 NULL
H(41,1)=[H’(k)+i] mod n 9 NULL
= [ H’(41) + 1 ] mod 10
= [ 1+ 1 ] mod 10
=2
Linear Probing
 H(k,i)=[H’(k)+i] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 21
i=1, n=10,k=41 2 41
3 NULL
Insert 41
4 NULL
 Hash Function  H’(41) = 41 % 5 95
10 6 NULL
1 7 NULL
Generate new key: 8 NULL
H(41,1)=[H’(k)+i] mod n 9 NULL
= [ H’(41) + 1 ] mod 10
= [ 1+ 1 ] mod 10
=2
Problem with Linear Probing
• One major problem with linear probing is primary.
• Primary clustering is a process in which a block of data is
formed in the hash table when collision is resolved.
• this cluster problem can be solved by quadratic probing
Key Data
0 20
1 21
2 22
3 NULL
4 NULL
5 NULL Table is Empty
6 NULL
7 87
8 107
9 NULL
Quadratic Probing
• Quadratic probing operates by taking the original hash value
and adding successive values of an arbitrary quadratic
polynomial to the starting value.
• New key will be created with the function
– H(k,i)=[H’(k)+i2] mod n

– Where
– H’(k) Generated key by hash function
– i2  Square of Probe number(0<=i<=n)
– n  Size of the hash table
– H(k,i)  New key after probing
Quadratic Probing
 H(k,i)=[H’(k)+i2] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 NULL
i=1, n=10 2 NULL
3 NULL
 Insert 95 4 NULL
5 NULL
6 NULL
Hash Function  H’(95) = 95 % 10
7 NULL
5
8 NULL
9 NULL
Quadratic Probing
 H(k,i)=[H’(k)+i2] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 NULL
i=1, n=10 2 NULL
3 NULL
 Insert 95 4 NULL
5 95
6 NULL
Hash Function  H’(95) = 95 % 10
7 NULL
5
8 NULL
 Insert 21 9 NULL

Hash Function  H’(21) = 21 % 10


1
Quadratic Probing
 H(k,i)=[H’(k)+i2] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 21
i=1, n=10 2 NULL
3 NULL
Insert 95 4 NULL
 Hash Function  H’(95) = 95 % 5 95
10 6 NULL

5 7 NULL
Insert 21 8 NULL
 Hash Function  H’(21) = 21 % 9 NULL
10
1
Insert 41
 Hash Function  H’(41) = 41 %
10
Quadratic Probing
 H(k,i)=[H’(k)+i2] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 21
i=1, n=10,k=41 2 NULL
3 NULL
Insert 41
4 NULL
 Hash Function  H’(41) = 41 % 5 95
10 6 NULL
1 7 NULL
Generate new key: 8 NULL
H(41,1)=[H’(k)+i2] mod n 9 NULL
= [ H’(41) + 1 ] mod 10
= [ 1+ 1 ] mod 10
=2
Quadratic Probing
 H(k,i)=[H’(k)+i2] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 21
i=1, n=10,k=41 2 41
3 NULL
Insert 41
4 NULL
 Hash Function  H’(41) = 41 % 5 95
10 6 NULL
1 7 NULL
Generate new key: 8 NULL
H(41,1)=[H’(k)+i2] mod n 9 NULL
= [ H’(41) + 1 ] mod 10
= [ 1+ 1 ] mod 10
=2
Quadratic Probing
 H(k,i)=[H’(k)+i2] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 21
i=1, n=10,k=51 2 41
3 NULL
Insert 51
4 NULL
 Hash Function  H’(51) = 51 % 5 95
10 6 NULL
1 7 NULL
Generate new key: 8 NULL
H(51,1)=[H’(k)+i2] mod n 9 NULL
= [ H’(51) + 1 ] mod 10
= [ 1+ 1 ] mod 10
=2
Quadratic Probing
Insert 51
Key Data
 Hash Function  H’(51) = 51 %
0 NULL
10
1 21
1
2 41
Generate new key:
3 NULL
H(51,1)=[H’(k)+i2] mod n 4 NULL
= [ H’(51) + 1 ] mod 10 5 95
= [ 1+ 1 ] mod 10 6 NULL
=2 7 NULL
8 NULL
i=2; 9 NULL
H(51,1)=[H’(k)+i2] mod n
= [ H’(51) + 4 ] mod 10
= [ 1+ 4 ] mod 10
=5
Quadratic Probing
Insert 51
Key Data
 Hash Function  H’(51) = 51 %
0 51
10
1 21
1
2 41
Generate new key:
3 NULL
H(51,1)=[H’(k)+i2] mod n 4 NULL
= [ H’(51) + 1 ] mod 10 5 95
= [ 1+ 1 ] mod 10 6 NULL
=2 7 NULL
8 NULL
i=2; i=3; 9 NULL
H(51,1)=[H’(k)+i2] mod n H(51,1)=[H’(k)+i2] mod n
= [ H’(51) + 4 ] mod 10 = [ H’(51) + 9 ] mod 10
= [ 1+ 4 ] mod 10 = [ 1+ 9 ] mod 10
=5 =0
Double Hashing
• Double hashing is technique in which a second hash
function is applied to the key when a collision occurs.
• By applying the second hash function we will get the
number of positions from the point of collision to insert.
• There are two important rules to be followed for the second
function
– It must never evaluate to zero
– must make sure that all cells can be probed
• The formula to be used for double hashing is
– H1(key)= key mod tablesize
– H2(key)=M-(key mod M)

– Where M prime number smaller than table size


Double Probing
  H1(key)= key mod Key Data
tablesize 0 NULL
  H2(key)=M-(key mod M) 1 NULL
2 NULL
3 NULL
Hash Function  H’(k) = k % 10
 Insert 95 4 NULL
5 NULL

Hash Function  H’(95) = 95 % 10 6 NULL


7 NULL
5
8 NULL
9 NULL
Double Probing
  H1(key)= key mod Key Data
tablesize 0 NULL
  H2(key)=M-(key mod M) 1 NULL
2 NULL
3 NULL
Hash Function  H’(k) = k % 10
 Insert 95 4 NULL
5 95

Hash Function  H’(95) = 95 % 10 6 NULL


7 NULL
5
8 NULL
 Insert 21 9 NULL

Hash Function  H’(21) = 21 % 10


1
Double Probing
  H1(key)= key mod Key Data
tablesize 0 NULL
  H2(key)=M-(key mod M) 1 21
2 NULL
3 NULL
Hash Function  H’(k) = k % 10
 Insert 95 4 NULL
5 95

Hash Function  H’(95) = 95 % 10 6 NULL


7 NULL
5
8 NULL
 Insert 21 9 NULL

Hash Function  H’(21) = 21 % 10


1
Double Probing
  H1(key)= key mod Key Data
tablesize 0 NULL
  H2(key)=M-(key mod M) 1 21
2 NULL
3 NULL
Hash Function  H’(k) = k % 10
 Insert 41 4 NULL
5 95
6 NULL
Hash Function  H’(41) = 41 % 10
7 NULL
1
8 NULL
Hash Function  H2(k) = M- (k % M) where M=7 9 NULL

= 7-(41 % 7)
=7 – 6
=1
That means we have to insert the element 41 at 1 place jump from 21
Double Probing
  H1(key)= key mod Key Data
tablesize 0 NULL
  H2(key)=M-(key mod M) 1 21
2 41
3 NULL
Hash Function  H’(k) = k % 10
 Insert 41 4 NULL
5 95
6 NULL
Hash Function  H’(41) = 41 % 10
7 NULL
1
8 NULL
Hash Function  H2(k) = M- (k % M) where M=7 9 NULL

= 7-(41 % 7)
=7 – 6
=1
That means we have to insert the element 41 at 1 place jump from 21
Rehashing
• In a hash table number of collisions increases when the
number of elements are increased.
• If collisions increases inserting keys into hash table takes more
time.
• Hash table occupancy defined by load factor.
• Load factor defines the hash table filled capacity.
• It can be calculated with no of elements and size of the hash
table.
– Load factor= No. of elements in hash table/size of the hash table
• If load factor multiply with 100 then we will get % of hash filled
– Load factor is 0  Hash is empty
– Load factor is 1  Hash is full
– Load factor is 0.5 half full
Rehashing
• Increasing no. of collisions will affect on performance of hash table.
• Create a new hash table with greater size is and redo the hashing
called Rehashing.
• In Rehashing old hash table values are stored in new hash table.
• This hash table creation depends on the load factor.
• New hash table size (N) is near prime number to double the old hash
size(2N).
• In General ,if load factor is more than 0.7 then rehashing is applied.
• New hash function for moving values is
• K’ = key % N’
• Rehashing done along with any another Collision Resolution Technique
Rehashing with Linear Probing
 H(k,i)=[H’(k)+i] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 NULL
i=1, n=10 2 NULL
3 NULL
 Insert 95 4 NULL
5 NULL
6 NULL
Hash Function  H’(95) = 95 % 10
7 NULL
5
8 NULL
9 NULL

E=0 , n=10
Load factor= 0/10 =0
Rehashing with Linear Probing
 H(k,i)=[H’(k)+i] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 NULL
i=1, n=10 2 NULL
3 NULL
 Insert 95 4 NULL
5 95
6 NULL
Hash Function  H’(95) = 95 % 10
7 NULL
5
8 NULL
 Insert 21 9 NULL

Hash Function  H’(21) = 21 % 10 E=1 , n=10


1 Load factor= 1/10 =0.1
Rehashing with Linear Probing
 H(k,i)=[H’(k)+i] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 21
i=1, n=10 2 NULL
3 NULL
Insert 95 4 NULL
 Hash Function  H’(95) = 95 % 5 95
10 6 NULL

5 7 NULL
Insert 21 8 NULL
 Hash Function  H’(21) = 21 % 9 NULL
10
1 E=2 , n=10
Insert 41
Load factor= 2/10 =0.2
 Hash Function  H’(41) = 41 %
10
Rehashing with Linear Probing
 H(k,i)=[H’(k)+i] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 21
i=1, n=10,k=41 2 41
3 NULL
Insert 41
4 NULL
 Hash Function  H’(41) = 41 % 5 95
10 6 NULL
1 7 NULL
Generate new key: 8 NULL
H(41,1)=[H’(k)+i] mod n 9 NULL
= [ H’(41) + 1 ] mod 10
= [ 1+ 1 ] mod 10 E=3 , n=10
=2 Load factor= 3/10 =0.3
Rehashing with Linear Probing
 H(k,i)=[H’(k)+i] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 21
i=1, n=10 2 41
3 NULL
Insert 88 4 NULL
 Hash Function  H’(88) = 88 % 5 95
10 6 NULL

8 7 NULL
 Insert 99 8 88
 Hash Function  H’(99) = 99 % 9 NULL
10
9
E=4 , n=10
Load factor= 4/10 =0.4
Rehashing with Linear Probing
 H(k,i)=[H’(k)+i] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 21
i=1, n=10 2 41
3 NULL
Insert 88 4 NULL
 Hash Function  H’(88) = 88 % 5 95
10 6 NULL

8 7 NULL
 Insert 99 8 88
 Hash Function  H’(99) = 99 % 9 99
10
9
E=5 , n=10
Load factor= 5/10 =0.5
Rehashing with Linear Probing
 H(k,i)=[H’(k)+i] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 21
i=1, n=10 2 41
3 NULL
Insert 66 4 NULL
 Hash Function  H’(66) = 66 % 5 95
10 6 66

6 7 NULL
 Insert 97 8 88
 Hash Function  H’(97) = 97 % 9 99
10
7
E=6 , n=10
Load factor= 6/10 =0.6
Rehashing with Linear Probing
 H(k,i)=[H’(k)+i] mod n Key Data
0 NULL
Hash Function  H’(k) = k % 10 1 21
i=1, n=10 2 41
3 NULL
Insert 66 4 NULL
 Hash Function  H’(66) = 66 % 5 95
10 6 66

6 7 97
 Insert 97 8 88
 Hash Function  H’(97) = 97 % 9 99
10
 7
Insert 33 E=7 , n=10
 Hash Function  H’(33) = 33 % Load factor= 7/10 =0.7 not > 0.
10
3 Now apply Rehashing
Rehashing with Linear Probing
 Rehashing
Key Data Key Data
2N= 2*10 =20
Nearest Prime 19 0 95 10 NULL
N’  19 new hash table size
1 NULL 11 NULL
Values to insert 2 21 12 NULL
21,41,95,66,97,88,99
3 41 13 NULL
K’ = k % 19  21 % 19  2
 41 %19  3 4 97 14 NULL
 95 % 19 0
 66 % 19 9
5 95 15 NULL
6 99 16 NULL
7 88 17 NULL
8 NULL 18 NULL
9 66 19 NULL

 97 %19  2
 88 % 19 7
 99 % 19 4
Extendible Hashing
• In open addressing collisions could cause several blocks to be
examined during a find even for a well distributed hash table. When
the table gets too full then an expensive rehashing step must be
performed.
• To avoid this problem Extendible hashing is used.
• Extendible hashing is technique which handles large amount of data.
• The data to be placed in the hash table is by extracting certain no. of
bits.
0 1 Directory
• Extendible hashing grow and shrink automatically.
(1) (1) Level

001 111
010
Bucket
Extendible Hashing
• The bucket can hold the data of its global depth
• If data in bucket is more than global depth then split the bucket and
double the directory.
• Example: Insert 1,4,5,7,8,10 and assign each page can hold 2 data
entries (depth is 2).
• We will extract last bit of data and insert the data into bucket
• Step1: insert 1, 4 0

• 1 binary  001 (1)


• 4 binary  100 001
100
Extendible Hashing
• Step2: insert 5
• Bucket is full hence double the directory and split the bucket

• 1 binary  001 0 1

• 4 binary  100
• 5 binary  101 (1) (1)
100 001
101
Extendible Hashing
• Step3: insert 7
• 7 binary  111
• Bucket is full hence double the directory and split the bucket.
• Consider last 2 bits 00 01 10 11

• 1 binary  001
• 4 binary  100 (2) (2) (2)

• 5 binary  101 100 001 111


101
• 7 binary  111
Extendible Hashing
• Step4: insert 8
• 1 binary  001
• 4 binary  100
• 5 binary  101 00 01 10 11

• 7 binary  111
• 8 binary  1000 (2) (2) (2)
100 001 111
1000 101
Extendible Hashing
• Step5: insert 10
• 1 binary  001
• 4 binary  100
• 5 binary  101 00 01 10 11

• 7 binary  111
• 8 binary  1000 (2) (2) (2)

• 10 binary  1010 100 001 1010 111


1000 101
Extendible Hashing
• Step1: Delete 10

• 10 binary  1010
00 01 10 11

(2) (2) (2)


100 001 111
1000 101
Extendible Hashing
• Step2: Delete 7

• 7 binary  111
00 01 10 11

(1) (1)
100 001
1000 101
Extendible Hashing
• Step2: Delete 7

• 7 binary  111
00 01

(1) (1)
100 001
1000 101
Thank you

You might also like