0% found this document useful (0 votes)
5 views

Data Structure Seminar

The document discusses rehashing and extendable hashing in data structures, focusing on their definitions, processes, and advantages. Rehashing involves resizing a hash table when it becomes too full, while extendable hashing is a dynamic technique that allows the hash table to grow and shrink based on data insertion. Key concepts include global and local depth, bucket splitting, and directory expansion.

Uploaded by

ashaazahmed2005
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Data Structure Seminar

The document discusses rehashing and extendable hashing in data structures, focusing on their definitions, processes, and advantages. Rehashing involves resizing a hash table when it becomes too full, while extendable hashing is a dynamic technique that allows the hash table to grow and shrink based on data insertion. Key concepts include global and local depth, bucket splitting, and directory expansion.

Uploaded by

ashaazahmed2005
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

• REHASHIN

G
• EXTENDIBLE
HASHING
Prepared by
Ashaaz Ahmed A
2nd Year CSE-A
REHASHING
• Rehashing in data structures is the process of resizing and
reorganizing a hash table when it becomes too full or inefficient
to handle the current set of keys.

• The size of table is doubled by creating a new


table.

• The size of the new hash table is mostly a


prime number.
Why Rehashing
Required?
• When hash table is completely full.
• With quadratic probing when table is half filled.
• When insertions fail due to overflow.

In these situations, we have to transfer entries from old table to the


new table by recomputing their positions using suitable hash
functions.
Pictorial
Representation

Hash
H(key)Function
= key mod tablesize
Examp
le:
Insert the elements
37,90,55,22,17,49,87.
Table size is 10
NOT
TheE:
table is almost full and if we try to insert more
elements collisions will occur and eventually further
insertions will fail. Hence we will rehash by doubling
the table size. The old table size is 10 then we should
double this size for new table, that becomes 20. But 20
is not a prime number, we will prefer to make the table
size as 23. Hence Rehashing is applied
Advantages :-
• It provides the programmer a flexibility to enlarge
the table size if is required.

• Only the size of table gets doubled with simple


hash function which avoids occurrence of
collisions.
EXTENDABLE HASHING
Extendable Hashing is a dynamic hashing technique & it is called dynamic hashing because data are
frequently inserted and due to which the hash table size gets changed quite often.

• The data to be placed in the hash table is by extracting certain number of bits.

• The extendible hash table grow and shrink in size.

• The extendible hashing scheme contains main memory (Directory) and one or more sub directories(buckets)
stored on disk.

• The hash table size is always 2d where d is called global depth. Each table entry points to one bucket.

• Each bucket is associated with local depth d’.


Important Terms
• Directories: The directories store addresses of the buckets.
• Buckets: The buckets are used to hash the actual data.
• Global Depth: It is the number of values associated with the Directories. They denote the number of bits
which are used by the hash function to categorize the keys.
• Local Depth: It is the same as that of Global Depth except for the fact that Local Depth is associated with
the buckets Local depth in accordance with the global depth is used to decide the action that need to be
performed in case an overflow occurs. Local Depth is always less than or equal to the
Global Depth.
• Bucket Splitting: When the number of elements in a bucket exceeds a particular size, then the bucket is
split into two parts.
• Directory Expansion: Directory Expansion takes place when a bucket overflows. Directory Expansion is
The last two bits of value 4 are 00, hence we will place them in Bucket # 1,
because the 00 index of main directory points to Bucket #1. Similarly other
elements are placed in appropriate bucket based on last 2 bits. For the sake of
understanding, the list of binary representation of the numbers used above is as
follows -

1 = 0001, 5 = 0101, 21=10101, 6 = 0110,

10 = 1010, 7 = 0111,
EXTENDIBILE HASHING Insertion -
Working
EXTENDIBILE HASHING Insertion -
Working
Step 1: If the target bucket does not overflow, simply insert data in
appropriate bucket based on bit extract.

Step 2: If bucket overflow happens, then if local depth is equal to


global depth and if the d bits are not enough to distingusih the search
values of overflown bucket, then directory gets doubled.

Step 3: If local depth is less than the global depth and if bucket gets
overflow, then there is no need to double the size of the directory.
EXAMPLE
Consider the following hash table and insert 14,20,24,18,22
Step 1: Insert 14
Binary representation of 14 is 1110 we will insert 14 in
Bucket #3. The Bucket #3 is not overflown, so insertion
of 14 in it is simply straight forward.
Step 2: Insert 20

Binary representation of 20 = 10100

Insert it in Bucket #1

Step 3: Insert 24

Binary representation of 24 = 11000

If we insert 24 in Bucket #1, then overflow will occur. As local depth d' of Bucket #1 = Global depth d
= 2. We need to double the size of main directory. Then increment the global depth. Rehash Bucket #1
to place the elements. Note that while rehashing for Bucket #1 elements, last 3 bits are considered.
Update local depth of Bucket #1 and the
Bucket that gets created as split image of
Bucket #1.
Step 4 : Insert 18
The binary representation of 18 = 10010. We will consider last two digits and
insert 18 in Bucket #3. (Because local depth of this bucket is 2).
Step 5: Insert 22

The binary representation of 22 = 10110. That means in 22 in Bucket #3. But as Bucket #3 is full
we need to create split image of Bucket #3 as Bucket #3'. There is no need to double the size of
directory as global depth (3) > local depth (2) . Now to rehash the values in Bucket #3 and Bucket
#3' we will consider last three bits. The local depth of Bucket #3 = Bucket #3' = 3. Thus 22 gets
inserted appropriately.
Points to Remember :
1. The maximum number of bits needed to tell which bucket an entry belongs to for
Directory is called global depth.

2. The number of bits used to determine if an entry belongs to particular which bucket is
called local depth.

3. The directory gets doubled only when bucket is full and local depth = global depth
before insertion.
EXTENDIBILE HASHING Deletion -
Working

Step-1 :The element can be removed from corresponding buckets and if bucke
becomes empty then it can be merged with split image bucket.

Step 2: If each directory element points to same bucket as its split image,
just half the directory.
SUMMARY

You might also like