SlideShare a Scribd company logo
1 of 21
Hash Tables
What is Hashing?
 Hashing is an algorithm (via a hash function) that maps large data sets
of variable length, called keys, to smaller data sets of a fixed length
 A hash table (or hash map) is a data structure that uses a hash
function to efficiently map keys to values, for efficient search and
retrieval
 Widely used in many kinds of computer software, particularly for
associative arrays, database indexing, caches, and sets
 Hash Table Data Structure : Purpose
 To support insertion, deletion and search in average case constant
time
 Assumption: Order of elements irrelevant
 ==> data structure *not* useful for if you want to maintain and retrieve some kind
of an order of the elements
 Hash function
 Hash[ “string key”] ==> integer value
Hash Function
• A hash function is a mathematical formula which, when applied
to a key, produces a value which can be used as an index for
the key in the hash table.
• The main aim of a hash function is that elements should
be uniformly distributed. It produces a unique set of integers
within some suitable range in order to reduce the number of
collisions.
Different Hash Functions
Division Method
This is the most simple method of hashing. Any integer, for example, x is divided by a num
and the remainder obtained is used as the hash.
Generally, M is chosen to be a prime number because a prime number increases the like
that the keys are mapped with uniformity in the output range of values.
This function could be represented as:
h(k) = k mod M
Multiplication Method
The Multiplication method has the following steps:
1.A constant is chosen which is between 0 and 1, say A.
3.The fractional part of kA is extracted.
4.The result of Step 3 is multiplied by the size of the hash table ( m).
This can be represented as:
h(k) = fractional_part[ m (kA mod 1) ]
The key k is multiplied by A.
Mid-Square Method
• The Mid-Square method is as follows:
1.The value of the key is squared. That is, k^2 is found.
2.The middle r digits of the result are extracted.
3.The result r is the hash obtained.
• The algorithm works well because most or all digits of the key-value
contribute to the resulting hash.
• The concept of a hash table is a generalized idea of an array where key
does not have to be an integer.
• We can have a name as a key, or for that matter any object as the key.
• The trick is to find a hash function to compute an index so that an object
can be stored at a specific location in a table such that it can easily be
found.
• Suppose we have a set of strings {“abc”, “def”, “ghi”} that we’d like to
store in a table.
• Our objective here is to find or update them quickly from a table, actually
in O(1).
• We are not concerned about ordering them or maintaining any order at
all.
• Let us think of a simple schema to do this. Suppose we assign “a” = 1,
“b”=2, … etc to all alphabetical characters.
• We can then simply compute a number for each of the strings by using
the sum of the characters as follows.
• “abc” = 1 + 2 + 3=6, “def” = 4 + 5 + 6=15 , “ghi” = 7 + 8 + 9=24
• If we assume that we have a table of size 5 to store these strings, we can
compute the location of the string by taking the sum mod 5.
• “abc” in 6 mod 5 = 1, “def” in 15 mod 5 = 0, and “ghi” in 24 mod 5 = 4 in
locations 1, 0 and 4 as follows:
Problem with Hashing
• First of all, the hash function we used, that is the sum of the letters, is a
bad one.
• In case we have permutations of the same letters, “abc”, “bac” etc in the
set, we will end up with the same value for the sum and hence the key.
• In this case, the strings would hash into the same location, creating what
we call a “collision”.
• Secondly, we need to find a good table size, preferably a prime number
so that even if the sums are different, then collisions can be avoided,
when we take mod of the sum to find the location.
Hashing with Chaining
• The Chaining is one collision resolution technique. We cannot avoid
collision, but we can try to reduce the collision, and try to store
multiple elements for same hash value.
• This technique suppose our hash function h(x) ranging from 0 to 6.
So for more than 7 elements, there must be some elements, that will
be places inside the same room. For that we will create a list to
store them accordingly. In each time we will add at the beginning of
the list to perform insertion in O(1) time
Let us see the following example to get better idea. If we have some elements like {15, 47, 23, 34, 85, 97, 65,
89, 70}. And our hash function is h(x) = x mod 7.
Open Addressing
• Once a collision takes place, open addressing (also known as closed
hashing ) computes new positions using a probe sequence and the
next record is stored in that position. There are some well-known probe
sequences:
1.Linear Probing: The interval between the probes is fixed to 1. This
means that the very next available position in the table would be tried.
2. Quadratic Probing: The interval between the probes increases
quadratically. This means that the next available position that would
be tried would increase quadratically.
Let us consider table Size = 7, hash function as Hash(x) = x % 7 and collision resolution strategy to be f(i) = i2 .
Insert = 22, 30, and 50.
Step2
Insert keys 22 and 30 in the hash table
•Step 3: Inserting 50
• Hash(50) = 50 % 7 = 1
• In our hash table slot 1 is already occupied. So, we will search for slot 1+12, i.e. 1+1 = 2,
• Again slot 2 is found occupied, so we will search for cell 1+22, i.e.1+4 = 5,
• Now, cell 5 is not occupied so we will place 50 in slot 5.
• Double Hashing: The interval between probes is fixed for each record
but the hash is computed again by double hashing.
• Insert the keys 27, 43, 92, 72 into the Hash Table of size 7. where first
hash-function is h1​(k) = k mod 7 and second hash-function is h2(k) = 1
+ (k mod 5)
• Step 1: Insert 27
• 27 % 7 = 6, location 6 is empty so insert 27 into 6 slot.
•Step 2: Insert 43
•43 % 7 = 1, location 1 is empty so insert 43 into 1 slot.
•Step 3: Insert 92
•92 % 7 = 6, but location 6 is already being occupied and this is a collision
•So we need to resolve this collision using double hashing.
hnew = [h1(92) + i * (h2(92)] % 7
= [6 + 1 * (1 + 92 % 5)] % 7
= 9 % 7
= 2
Now, as 2 is an empty slot,
so we can insert 92 into 2nd slot.
•Insert 72
•72 % 7 = 2, but location 2 is already being occupied and this is a collision.
•So we need to resolve this collision using double hashing.
hnew = [h1(72) + i * (h2(72)] % 7
= [2 + 1 * (1 + 72 % 5)] % 7
= 5 % 7
= 5,
Now, as 5 is an empty slot,
so we can insert 72 into 5th slot.
Insert key 72 in the hash table

More Related Content

Similar to Lecture14_15_Hashing.pptx

HASHING IS NOT YASH IT IS HASH.pptx
HASHING IS NOT YASH IT IS HASH.pptxHASHING IS NOT YASH IT IS HASH.pptx
HASHING IS NOT YASH IT IS HASH.pptxJITTAYASHWANTHREDDY
 
Concept of hashing
Concept of hashingConcept of hashing
Concept of hashingRafi Dar
 
Hashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniquesHashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniquesssuserec8a711
 
11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithm11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithmfarhankhan89766
 
358 33 powerpoint-slides_15-hashing-collision_chapter-15
358 33 powerpoint-slides_15-hashing-collision_chapter-15358 33 powerpoint-slides_15-hashing-collision_chapter-15
358 33 powerpoint-slides_15-hashing-collision_chapter-15sumitbardhan
 
DS Unit 1.pptx
DS Unit 1.pptxDS Unit 1.pptx
DS Unit 1.pptxchin463670
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec IISajid Marwat
 
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Kuntal Bhowmick
 
Hashing and File Structures in Data Structure.pdf
Hashing and File Structures in Data Structure.pdfHashing and File Structures in Data Structure.pdf
Hashing and File Structures in Data Structure.pdfJaithoonBibi
 

Similar to Lecture14_15_Hashing.pptx (20)

HASHING IS NOT YASH IT IS HASH.pptx
HASHING IS NOT YASH IT IS HASH.pptxHASHING IS NOT YASH IT IS HASH.pptx
HASHING IS NOT YASH IT IS HASH.pptx
 
8. Hash table
8. Hash table8. Hash table
8. Hash table
 
Concept of hashing
Concept of hashingConcept of hashing
Concept of hashing
 
Hashing 1
Hashing 1Hashing 1
Hashing 1
 
Hashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniquesHashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniques
 
L21_Hashing.pdf
L21_Hashing.pdfL21_Hashing.pdf
L21_Hashing.pdf
 
11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithm11_hashtable-1.ppt. Data structure algorithm
11_hashtable-1.ppt. Data structure algorithm
 
Unit viii searching and hashing
Unit   viii searching and hashing Unit   viii searching and hashing
Unit viii searching and hashing
 
Quadratic probing
Quadratic probingQuadratic probing
Quadratic probing
 
Hashing
HashingHashing
Hashing
 
Hashing
HashingHashing
Hashing
 
358 33 powerpoint-slides_15-hashing-collision_chapter-15
358 33 powerpoint-slides_15-hashing-collision_chapter-15358 33 powerpoint-slides_15-hashing-collision_chapter-15
358 33 powerpoint-slides_15-hashing-collision_chapter-15
 
DS Unit 1.pptx
DS Unit 1.pptxDS Unit 1.pptx
DS Unit 1.pptx
 
Hashing
HashingHashing
Hashing
 
Ch17 Hashing
Ch17 HashingCh17 Hashing
Ch17 Hashing
 
Hashing
HashingHashing
Hashing
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec II
 
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)Hashing notes data structures (HASHING AND HASH FUNCTIONS)
Hashing notes data structures (HASHING AND HASH FUNCTIONS)
 
Hash tables
Hash tablesHash tables
Hash tables
 
Hashing and File Structures in Data Structure.pdf
Hashing and File Structures in Data Structure.pdfHashing and File Structures in Data Structure.pdf
Hashing and File Structures in Data Structure.pdf
 

Recently uploaded

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 

Lecture14_15_Hashing.pptx

  • 2. What is Hashing?  Hashing is an algorithm (via a hash function) that maps large data sets of variable length, called keys, to smaller data sets of a fixed length  A hash table (or hash map) is a data structure that uses a hash function to efficiently map keys to values, for efficient search and retrieval  Widely used in many kinds of computer software, particularly for associative arrays, database indexing, caches, and sets
  • 3.  Hash Table Data Structure : Purpose  To support insertion, deletion and search in average case constant time  Assumption: Order of elements irrelevant  ==> data structure *not* useful for if you want to maintain and retrieve some kind of an order of the elements  Hash function  Hash[ “string key”] ==> integer value
  • 4. Hash Function • A hash function is a mathematical formula which, when applied to a key, produces a value which can be used as an index for the key in the hash table. • The main aim of a hash function is that elements should be uniformly distributed. It produces a unique set of integers within some suitable range in order to reduce the number of collisions.
  • 5. Different Hash Functions Division Method This is the most simple method of hashing. Any integer, for example, x is divided by a num and the remainder obtained is used as the hash. Generally, M is chosen to be a prime number because a prime number increases the like that the keys are mapped with uniformity in the output range of values. This function could be represented as: h(k) = k mod M Multiplication Method The Multiplication method has the following steps: 1.A constant is chosen which is between 0 and 1, say A. 3.The fractional part of kA is extracted. 4.The result of Step 3 is multiplied by the size of the hash table ( m). This can be represented as: h(k) = fractional_part[ m (kA mod 1) ] The key k is multiplied by A.
  • 6. Mid-Square Method • The Mid-Square method is as follows: 1.The value of the key is squared. That is, k^2 is found. 2.The middle r digits of the result are extracted. 3.The result r is the hash obtained. • The algorithm works well because most or all digits of the key-value contribute to the resulting hash.
  • 7. • The concept of a hash table is a generalized idea of an array where key does not have to be an integer. • We can have a name as a key, or for that matter any object as the key. • The trick is to find a hash function to compute an index so that an object can be stored at a specific location in a table such that it can easily be found.
  • 8. • Suppose we have a set of strings {“abc”, “def”, “ghi”} that we’d like to store in a table. • Our objective here is to find or update them quickly from a table, actually in O(1). • We are not concerned about ordering them or maintaining any order at all. • Let us think of a simple schema to do this. Suppose we assign “a” = 1, “b”=2, … etc to all alphabetical characters. • We can then simply compute a number for each of the strings by using the sum of the characters as follows. • “abc” = 1 + 2 + 3=6, “def” = 4 + 5 + 6=15 , “ghi” = 7 + 8 + 9=24 • If we assume that we have a table of size 5 to store these strings, we can compute the location of the string by taking the sum mod 5.
  • 9. • “abc” in 6 mod 5 = 1, “def” in 15 mod 5 = 0, and “ghi” in 24 mod 5 = 4 in locations 1, 0 and 4 as follows:
  • 10. Problem with Hashing • First of all, the hash function we used, that is the sum of the letters, is a bad one. • In case we have permutations of the same letters, “abc”, “bac” etc in the set, we will end up with the same value for the sum and hence the key. • In this case, the strings would hash into the same location, creating what we call a “collision”. • Secondly, we need to find a good table size, preferably a prime number so that even if the sums are different, then collisions can be avoided, when we take mod of the sum to find the location.
  • 11. Hashing with Chaining • The Chaining is one collision resolution technique. We cannot avoid collision, but we can try to reduce the collision, and try to store multiple elements for same hash value. • This technique suppose our hash function h(x) ranging from 0 to 6. So for more than 7 elements, there must be some elements, that will be places inside the same room. For that we will create a list to store them accordingly. In each time we will add at the beginning of the list to perform insertion in O(1) time
  • 12. Let us see the following example to get better idea. If we have some elements like {15, 47, 23, 34, 85, 97, 65, 89, 70}. And our hash function is h(x) = x mod 7.
  • 13. Open Addressing • Once a collision takes place, open addressing (also known as closed hashing ) computes new positions using a probe sequence and the next record is stored in that position. There are some well-known probe sequences: 1.Linear Probing: The interval between the probes is fixed to 1. This means that the very next available position in the table would be tried.
  • 14. 2. Quadratic Probing: The interval between the probes increases quadratically. This means that the next available position that would be tried would increase quadratically.
  • 15. Let us consider table Size = 7, hash function as Hash(x) = x % 7 and collision resolution strategy to be f(i) = i2 . Insert = 22, 30, and 50.
  • 16. Step2 Insert keys 22 and 30 in the hash table
  • 17. •Step 3: Inserting 50 • Hash(50) = 50 % 7 = 1 • In our hash table slot 1 is already occupied. So, we will search for slot 1+12, i.e. 1+1 = 2, • Again slot 2 is found occupied, so we will search for cell 1+22, i.e.1+4 = 5, • Now, cell 5 is not occupied so we will place 50 in slot 5.
  • 18. • Double Hashing: The interval between probes is fixed for each record but the hash is computed again by double hashing. • Insert the keys 27, 43, 92, 72 into the Hash Table of size 7. where first hash-function is h1​(k) = k mod 7 and second hash-function is h2(k) = 1 + (k mod 5) • Step 1: Insert 27 • 27 % 7 = 6, location 6 is empty so insert 27 into 6 slot.
  • 19. •Step 2: Insert 43 •43 % 7 = 1, location 1 is empty so insert 43 into 1 slot.
  • 20. •Step 3: Insert 92 •92 % 7 = 6, but location 6 is already being occupied and this is a collision •So we need to resolve this collision using double hashing. hnew = [h1(92) + i * (h2(92)] % 7 = [6 + 1 * (1 + 92 % 5)] % 7 = 9 % 7 = 2 Now, as 2 is an empty slot, so we can insert 92 into 2nd slot.
  • 21. •Insert 72 •72 % 7 = 2, but location 2 is already being occupied and this is a collision. •So we need to resolve this collision using double hashing. hnew = [h1(72) + i * (h2(72)] % 7 = [2 + 1 * (1 + 72 % 5)] % 7 = 5 % 7 = 5, Now, as 5 is an empty slot, so we can insert 72 into 5th slot. Insert key 72 in the hash table