SlideShare a Scribd company logo
1 of 23
HASHING
• Hashing is the effective of storing the elements
in some data structure.
• It allows to reduce the number of comparisons.
• Using this technique we can obtain the concept
of direct access of stored record.
• Two concepts used regarding hashing those are
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.
• Every entry in the table is associated with some
key.
• Ex.. Employee record in the hash table, the
employee ID will work as a key.
• Using the hash key the required piece of data can
be searched in the hash table by few or more
comparisons.
• Searching time is dependent upon the size of the
hash table.
• HASH FUNCTION:
• Hash function is a function which is used to put
the data in the hash table.
• One can use the same function to retrieve the
data from the hash table.
• The integer returned by the hash function is
called hash key.
• Each location in the hash table is called Cell or
Bucket.
HASHING METHODS
– DIVISION METHOD
– MID SQUARE
– MULTIPLICATIVE HASH FUNCTION
– DIGIT FOLDING
– DIGIT ANALYSIS
Division method:
The hash function depends upon the remainder of
division.
Divisor is the table length.
If the record 54,72,89,37 is to be placed in the hash
table and if the table size is 10 then
h(key)=record % table size
54%10=4
72%10=2
89%10=9
37%10=7
0
1
2
3
4
5
6
7
8
9
54
72
89
37
Mid square:
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 preprocessed to
produce a number.
If we want to place a record 3111 then
(3111)2 =9678321
For the hash table of size 1000
H(3111)=783(the middle 3 digits)
Multiplicative hash function:
The given record is multiplied by some constant
value. The formula for computing the hash key is
H(key)=floor(p*(fractional part of key*A))
p is integer constant
A is the constant real integer
Donald Knuth is suggested to use constant
A=0.61803398987
If key 107 and p=20 then
H(key)=floor(20*(107*0.61803398987)
=floor(1322.5927383218)
=1322
At 1322 location in the hash table the record 107
will be placed
• Digit Folding:
The key is divided into separate parts and using some
simple operations these parts are combined to produce
the hash key.
For example, consider a record 12365412 then it is
divided into separate parts 123 654 12 and these are
added together
H(Key)=123+654+12
=0789
The record will be placed at location 789 in the hash
table.
• A situation when the resultant hashes for two or
more data elements in the data set U, maps to the
same location in the hash table, is called a hash
collision.
There are different methods for detecting collisions
and overflows in the Hash table:
• Chaining
• Open addressing(Linear probing)
• Quadratic Probing
• Double Hashing
Chaining or Separate Chaining:
• In collision handling method chaining is a concept
which introduces an additional field with data i.e.
chain.
• A separate chain table is maintained for colliding
data.
• When collision occurs then a linked list(chain) is
maintained at the home bucket.
For example:
Consider keys to be placed in their home buckets are
131,3,4,21,61,24,7,97,8,9
Then we will apply a hash function as
H(key)=key%Table size
•A chain is maintained for
colliding elements.
• For instance 131 has a home
bucket (key) 1.
•Similarly keys 21 and 61
demand for home bucket 1.
•Hence a chain is maintained at
index 1.
•Similarly the chain at index 4
and 7 is maintained
Linear Probing(Open addressing):
• This is the easiest method of handling collision.
• When collision occurs i.e. when two records demand
for the same home bucket.
• In the hash table then collision can be solved by
placing the second record linearly down whenever
the empty bucket is found.
• When use linear probing, the hash table is
represented as a one-dimensional array with indices
that range from 0 to the desired table size-1.
14
Disadvantage of Linear Probing: Primary Clustering
• Linear probing is subject to a primary clustering phenomenon.
• Elements tend to cluster around table locations that they originally hash to.
• Primary clusters can combine to form larger clusters. This leads to long probe
sequences and hence deterioration in hash table efficiency.
Example of a primary cluster: Insert keys: 18, 41, 22, 44, 59, 32, 31, 73, in this order, in an
originally empty hash table of size 13, using the hash function h(key) = key % 13 and c(i) = i:
h(18) = 5
h(41) = 2
h(22) = 9
h(44) = 5+1
h(59) = 7
h(32) = 6+1+1
h(31) = 5+1+1+1+1+1
h(73) = 8+1+1+1
Quadratic Probing:
• Quadratic probing operates by taking the original
hash values and adding successive values of an
arbitrary quadratic polynomial to the starting value.
• This method uses following formula
Hi(key)=(Hash(key)+i2))%m
Where m can be a table size or any prime number.
For example: if we have to insert following elements in the
hash table with table size 10:
37,90,55,22,11,17,49,87.
• 37,90,55,22,11,17,49,87.
We will fill the hash table step by step
37%10=7
90%10=0
55%10=5
22%10=2
11%10=1
0 90
1 11
2 22
3
4
5 55
6
7 37
8
9
Double Hashing:
Double hashing is a technique in which a second
hash function is applied to the key when
collision occurs.
By applying the second hash function we will get
the number of positions from the point of
collision to insert.
Formula used for double hashing is
H1(key)=key mod table size
H2(key)=M-(key mod M)
Where M is a prime number smaller than the size of the table.
Consider the following elements to be placed in the hash table
of size 10
37,90,45,22,17,49,55
H1(37)=37%10=7
H1(90)=90%10=0
H1(45)=45%10=5
H1(22)=22%10=2
H1(49)=49%10=9
H1(55)=55%10=5
H1(17)=17%10=7
H1(55)=55%10=5
0
1
2
3
4
5
6
7
8
9 49
37
45
22
90
Now 17 is to be inserted then
H1(17)=17%10=7
H2(key)=M-(key % M)
Here M is a prime number smaller than the size of
the table .
Prime number smaller than table size 10 is 7
Hence M=7
H2(17)=7-(17%7)
=7-3=4
That means we have to insert the element 17 at 4
places from 37, i.e, we have to take 4 jumps.
17 will be placed at index 1
0
1
2
3
4
5
6
7
8
9
37
90
45
22
17
EXAMPLE:
• Hash the following in a table of size 11. Using linear
probing , Quadratic probing collision resolving
techniques 23,0,52,61,78,33,100,8,90,10,14

More Related Content

Similar to HASHING TECHNIQUES FOR DATA STORAGE AND RETRIEVAL

Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptxAgonySingh
 
Hashing using a different methods of technic
Hashing using a different methods of technicHashing using a different methods of technic
Hashing using a different methods of techniclokaprasaadvs
 
Concept of hashing
Concept of hashingConcept of hashing
Concept of hashingRafi Dar
 
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
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec IISajid Marwat
 
Hash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptxHash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptxmy6305874
 
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptxunit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptxBabaShaikh3
 

Similar to HASHING TECHNIQUES FOR DATA STORAGE AND RETRIEVAL (20)

lecture10.ppt
lecture10.pptlecture10.ppt
lecture10.ppt
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Unit viii searching and hashing
Unit   viii searching and hashing Unit   viii searching and hashing
Unit viii searching and hashing
 
Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptx
 
Hashing using a different methods of technic
Hashing using a different methods of technicHashing using a different methods of technic
Hashing using a different methods of technic
 
Concept of hashing
Concept of hashingConcept of hashing
Concept of 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
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec II
 
Unit4 Part3.pptx
Unit4 Part3.pptxUnit4 Part3.pptx
Unit4 Part3.pptx
 
Hash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptxHash in datastructures by using the c language.pptx
Hash in datastructures by using the c language.pptx
 
4.4 hashing
4.4 hashing4.4 hashing
4.4 hashing
 
8. Hash table
8. Hash table8. Hash table
8. Hash table
 
Hashing
HashingHashing
Hashing
 
Hashing
HashingHashing
Hashing
 
Hashing 1
Hashing 1Hashing 1
Hashing 1
 
Hashing
HashingHashing
Hashing
 
L21_Hashing.pdf
L21_Hashing.pdfL21_Hashing.pdf
L21_Hashing.pdf
 
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptxunit-1-dsa-hashing-2022_compressed-1-converted.pptx
unit-1-dsa-hashing-2022_compressed-1-converted.pptx
 
Chapter 12 ds
Chapter 12 dsChapter 12 ds
Chapter 12 ds
 
Hashing
HashingHashing
Hashing
 

Recently uploaded

chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 

Recently uploaded (20)

chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 

HASHING TECHNIQUES FOR DATA STORAGE AND RETRIEVAL

  • 2. • Hashing is the effective of storing the elements in some data structure. • It allows to reduce the number of comparisons. • Using this technique we can obtain the concept of direct access of stored record. • Two concepts used regarding hashing those are HASH TABLE & HASH FUNCTION.
  • 3. 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. • Every entry in the table is associated with some key. • Ex.. Employee record in the hash table, the employee ID will work as a key. • Using the hash key the required piece of data can be searched in the hash table by few or more comparisons. • Searching time is dependent upon the size of the hash table.
  • 4. • HASH FUNCTION: • Hash function is a function which is used to put the data in the hash table. • One can use the same function to retrieve the data from the hash table. • The integer returned by the hash function is called hash key. • Each location in the hash table is called Cell or Bucket.
  • 5. HASHING METHODS – DIVISION METHOD – MID SQUARE – MULTIPLICATIVE HASH FUNCTION – DIGIT FOLDING – DIGIT ANALYSIS
  • 6. Division method: The hash function depends upon the remainder of division. Divisor is the table length. If the record 54,72,89,37 is to be placed in the hash table and if the table size is 10 then h(key)=record % table size 54%10=4 72%10=2 89%10=9 37%10=7 0 1 2 3 4 5 6 7 8 9 54 72 89 37
  • 7. Mid square: 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 preprocessed to produce a number. If we want to place a record 3111 then (3111)2 =9678321 For the hash table of size 1000 H(3111)=783(the middle 3 digits)
  • 8. Multiplicative hash function: The given record is multiplied by some constant value. The formula for computing the hash key is H(key)=floor(p*(fractional part of key*A)) p is integer constant A is the constant real integer Donald Knuth is suggested to use constant A=0.61803398987 If key 107 and p=20 then H(key)=floor(20*(107*0.61803398987) =floor(1322.5927383218) =1322 At 1322 location in the hash table the record 107 will be placed
  • 9. • Digit Folding: The key is divided into separate parts and using some simple operations these parts are combined to produce the hash key. For example, consider a record 12365412 then it is divided into separate parts 123 654 12 and these are added together H(Key)=123+654+12 =0789 The record will be placed at location 789 in the hash table.
  • 10. • A situation when the resultant hashes for two or more data elements in the data set U, maps to the same location in the hash table, is called a hash collision. There are different methods for detecting collisions and overflows in the Hash table: • Chaining • Open addressing(Linear probing) • Quadratic Probing • Double Hashing
  • 11. Chaining or Separate Chaining: • In collision handling method chaining is a concept which introduces an additional field with data i.e. chain. • A separate chain table is maintained for colliding data. • When collision occurs then a linked list(chain) is maintained at the home bucket.
  • 12. For example: Consider keys to be placed in their home buckets are 131,3,4,21,61,24,7,97,8,9 Then we will apply a hash function as H(key)=key%Table size •A chain is maintained for colliding elements. • For instance 131 has a home bucket (key) 1. •Similarly keys 21 and 61 demand for home bucket 1. •Hence a chain is maintained at index 1. •Similarly the chain at index 4 and 7 is maintained
  • 13. Linear Probing(Open addressing): • This is the easiest method of handling collision. • When collision occurs i.e. when two records demand for the same home bucket. • In the hash table then collision can be solved by placing the second record linearly down whenever the empty bucket is found. • When use linear probing, the hash table is represented as a one-dimensional array with indices that range from 0 to the desired table size-1.
  • 14. 14 Disadvantage of Linear Probing: Primary Clustering • Linear probing is subject to a primary clustering phenomenon. • Elements tend to cluster around table locations that they originally hash to. • Primary clusters can combine to form larger clusters. This leads to long probe sequences and hence deterioration in hash table efficiency. Example of a primary cluster: Insert keys: 18, 41, 22, 44, 59, 32, 31, 73, in this order, in an originally empty hash table of size 13, using the hash function h(key) = key % 13 and c(i) = i: h(18) = 5 h(41) = 2 h(22) = 9 h(44) = 5+1 h(59) = 7 h(32) = 6+1+1 h(31) = 5+1+1+1+1+1 h(73) = 8+1+1+1
  • 15. Quadratic Probing: • Quadratic probing operates by taking the original hash values and adding successive values of an arbitrary quadratic polynomial to the starting value. • This method uses following formula Hi(key)=(Hash(key)+i2))%m Where m can be a table size or any prime number. For example: if we have to insert following elements in the hash table with table size 10: 37,90,55,22,11,17,49,87.
  • 16. • 37,90,55,22,11,17,49,87. We will fill the hash table step by step 37%10=7 90%10=0 55%10=5 22%10=2 11%10=1 0 90 1 11 2 22 3 4 5 55 6 7 37 8 9
  • 17.
  • 18.
  • 19. Double Hashing: Double hashing is a technique in which a second hash function is applied to the key when collision occurs. By applying the second hash function we will get the number of positions from the point of collision to insert.
  • 20. Formula used for double hashing is H1(key)=key mod table size H2(key)=M-(key mod M) Where M is a prime number smaller than the size of the table. Consider the following elements to be placed in the hash table of size 10 37,90,45,22,17,49,55 H1(37)=37%10=7 H1(90)=90%10=0 H1(45)=45%10=5 H1(22)=22%10=2 H1(49)=49%10=9 H1(55)=55%10=5 H1(17)=17%10=7 H1(55)=55%10=5 0 1 2 3 4 5 6 7 8 9 49 37 45 22 90
  • 21. Now 17 is to be inserted then H1(17)=17%10=7 H2(key)=M-(key % M) Here M is a prime number smaller than the size of the table . Prime number smaller than table size 10 is 7 Hence M=7 H2(17)=7-(17%7) =7-3=4 That means we have to insert the element 17 at 4 places from 37, i.e, we have to take 4 jumps. 17 will be placed at index 1
  • 23. EXAMPLE: • Hash the following in a table of size 11. Using linear probing , Quadratic probing collision resolving techniques 23,0,52,61,78,33,100,8,90,10,14