SlideShare a Scribd company logo
1 of 12
• Concept Of hashing
• Need of Hashing
• Hash Collision
• Dealing with Hash Collision
• Resolving Hash Collisions by Open
  Addressing
• Primary clustering
• Double Rehash
Concept Of hashing
• Hashing: hashing is a technique for performing almost
  constant time in case of insertion deletion and find
  operation.
• taking a very simple example, as array with its index
  as key is the example of table.
• So each index (key) can be used for accessing values
  in the constant search time.
• Mapping key must be simple to compute and must help
  in identifying the associated records.
• Function that help us in generating such type of keys
  is termed as Hash Function.
Hashing
• let h(key) is hashing function that returns the hash
  code. h(key) = key%1000, which can produce any value
  between 0 and 999. as shown in figure:
Need of Hashing
• Hashing maps large data sets of variable length to
  smaller data sets of a fixed length. For example, an
  inventory file of a company having more than 100
  items and the key to each record is a seven digit part
  number. To use direct indexing using entire seven
  digit key, an array of 10 million elements would be
  required. Which clearly is wastage of space, since
  company is unlikely to stock more than few thousand
  parts.
• Hence hashing provides an alternative to convert
  seven digit key into an integer within limited range.
  The values returned by a hash function are called
  hash values, hash codes.
• Suppose two keys k1 and k2 hashes
  such that h(k1) = h(k2). Here two
  keys hashes into the same value and
  are supposed to occupy same slot in
  hash table ,which is unacceptable.
• Such a situation is termed as hash
  collision.
Dealing with Hash Collision
• Two methods to deal with hash collision are:
• Rehashing and Chaining
  Rehashing: invokes a secondary hash function
  (say Rh(key)), which is applied successively until
  an empty slot is found, where a record can be
  placed.

  Chaining: builds a Linked list of items whose key
  hashes to same value. During search this short
  linked list is traversed sequentially for the desired
  key. This technique requires extra link field to
  each table position.
hashing
Analysis:
• The worst case running time for insertion is
  O(1).
• Deletion of an element x can be accomplished
  in O(1) time if the lists are doubly linked.
• In the worst case behaviour of chain-hashing,
  all n keys hash to the same slot, creating a
  list of length n. The worst-case time for
  search is thus θ(n) plus the time to compute
  the hash function.
A good hash function is one that minimizes
  collision and spreads the records uniformly
  throughout the table. that is why it is
  desirable to have larger array size than
  actual number of records.
      More formally, suppose we want to store
  a set of size n in a table of size m. The
  ratio α = n/m is called a load factor, that
  is, the average number of elements stored
  in a Table.
Resolving Hash Collisions by
     Open Addressing
• Simplest method of resolving the hash
  collision is to place record into the next
  available position in the array.
• e.g. if key = 7803497.
• Then using hash function h(key) = key%
  1000 will produce 497. However if the
  497th position is already occupied by key =
  2885497, then next available position is
  chosen.
• The above technique is termed as Linear
  probing.
• the approach however a some pitfall called
  primary clustering problem.
• Primary clustering: the phenomenon
  where two keys that hashes into
  different values compete with each
  other in successive rehashes. Primary
  clustering is the result of the
  formation of blocks of occupied
  positions.
Eliminating primary
               clustering
Solution 1: allow the rehash function to depend on
the number of times the particular function is
applied for hash value.
Rh(I,j) yields I the hash value if the key is being
rehashed for jth time.
ist rehash yeilds rh1 = rh(h(key),1)
2nd rehash yeilds rh2 =rh(rh1 +2)%tablesize and so
on.
Solution 2: rather than always moving one spot,
move i2 spots from the point of collision, where i is
the number of attempts to resolve the collision. Ie.
The rehash of h(key) will be (h(key)+ sqr(i))%table
size. The method is called as Quadratic Rehash.
Double Rehash
• Both the solutions for eliminating the primary
  clustering suffers from another pitfall called
  secondary clustering. A phenomenon in which two
  keys hashes into same hash value then follows the
  same rehash path.
• One way of eliminating all types of clustering is to
  use double hash technique, which uses two hash
  functions: h1(key) and h2(key). The h1(key)
  determines the location for insertion, if occupied,
  then rehash function rh(i+h2(key))%tablesize is
  successively used untill an empty location is found.

More Related Content

What's hot (20)

Heap sort
Heap sortHeap sort
Heap sort
 
Hashing
HashingHashing
Hashing
 
Data Structure and Algorithms Hashing
Data Structure and Algorithms HashingData Structure and Algorithms Hashing
Data Structure and Algorithms Hashing
 
Hashing and separate chain
Hashing and separate chainHashing and separate chain
Hashing and separate chain
 
Hashing
HashingHashing
Hashing
 
Hashing and Hashtable, application of hashing, advantages of hashing, disadva...
Hashing and Hashtable, application of hashing, advantages of hashing, disadva...Hashing and Hashtable, application of hashing, advantages of hashing, disadva...
Hashing and Hashtable, application of hashing, advantages of hashing, disadva...
 
Hash table
Hash tableHash table
Hash table
 
Hash tables
Hash tablesHash tables
Hash tables
 
Hashing
HashingHashing
Hashing
 
Chapter 12 ds
Chapter 12 dsChapter 12 ds
Chapter 12 ds
 
Hashing In Data Structure
Hashing In Data Structure Hashing In Data Structure
Hashing In Data Structure
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
 
linear probing
linear probinglinear probing
linear probing
 
Heaps
HeapsHeaps
Heaps
 
Hashing
HashingHashing
Hashing
 
Hashing
HashingHashing
Hashing
 
Advanced data structures vol. 1
Advanced data structures   vol. 1Advanced data structures   vol. 1
Advanced data structures vol. 1
 
Hashing
HashingHashing
Hashing
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
 
Hashing
HashingHashing
Hashing
 

Similar to Concept of hashing

Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptxkratika64
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptxAgonySingh
 
Lecture14_15_Hashing.pptx
Lecture14_15_Hashing.pptxLecture14_15_Hashing.pptx
Lecture14_15_Hashing.pptxSLekshmiNair
 
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
 
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
 
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
 
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
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec IISajid Marwat
 
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
 
Hash presentation
Hash presentationHash presentation
Hash presentationomercode
 
Skiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sortingSkiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sortingzukun
 

Similar to Concept of hashing (20)

Hashing.pptx
Hashing.pptxHashing.pptx
Hashing.pptx
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Lecture14_15_Hashing.pptx
Lecture14_15_Hashing.pptxLecture14_15_Hashing.pptx
Lecture14_15_Hashing.pptx
 
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
 
Hashing
HashingHashing
Hashing
 
LECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdfLECT 10, 11-DSALGO(Hashing).pdf
LECT 10, 11-DSALGO(Hashing).pdf
 
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
 
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
 
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
 
HASHING.ppt.pptx
HASHING.ppt.pptxHASHING.ppt.pptx
HASHING.ppt.pptx
 
Hashing .pptx
Hashing .pptxHashing .pptx
Hashing .pptx
 
Advance algorithm hashing lec II
Advance algorithm hashing lec IIAdvance algorithm hashing lec II
Advance algorithm hashing lec II
 
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
 
Hash presentation
Hash presentationHash presentation
Hash presentation
 
Unit4 Part3.pptx
Unit4 Part3.pptxUnit4 Part3.pptx
Unit4 Part3.pptx
 
Hashing
HashingHashing
Hashing
 
13-hashing.ppt
13-hashing.ppt13-hashing.ppt
13-hashing.ppt
 
Quadratic probing
Quadratic probingQuadratic probing
Quadratic probing
 
Hash pre
Hash preHash pre
Hash pre
 
Skiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sortingSkiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sorting
 

Recently uploaded

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
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
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 

Recently uploaded (20)

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
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
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 

Concept of hashing

  • 1. • Concept Of hashing • Need of Hashing • Hash Collision • Dealing with Hash Collision • Resolving Hash Collisions by Open Addressing • Primary clustering • Double Rehash
  • 2. Concept Of hashing • Hashing: hashing is a technique for performing almost constant time in case of insertion deletion and find operation. • taking a very simple example, as array with its index as key is the example of table. • So each index (key) can be used for accessing values in the constant search time. • Mapping key must be simple to compute and must help in identifying the associated records. • Function that help us in generating such type of keys is termed as Hash Function.
  • 3. Hashing • let h(key) is hashing function that returns the hash code. h(key) = key%1000, which can produce any value between 0 and 999. as shown in figure:
  • 4. Need of Hashing • Hashing maps large data sets of variable length to smaller data sets of a fixed length. For example, an inventory file of a company having more than 100 items and the key to each record is a seven digit part number. To use direct indexing using entire seven digit key, an array of 10 million elements would be required. Which clearly is wastage of space, since company is unlikely to stock more than few thousand parts. • Hence hashing provides an alternative to convert seven digit key into an integer within limited range. The values returned by a hash function are called hash values, hash codes.
  • 5. • Suppose two keys k1 and k2 hashes such that h(k1) = h(k2). Here two keys hashes into the same value and are supposed to occupy same slot in hash table ,which is unacceptable. • Such a situation is termed as hash collision.
  • 6. Dealing with Hash Collision • Two methods to deal with hash collision are: • Rehashing and Chaining Rehashing: invokes a secondary hash function (say Rh(key)), which is applied successively until an empty slot is found, where a record can be placed. Chaining: builds a Linked list of items whose key hashes to same value. During search this short linked list is traversed sequentially for the desired key. This technique requires extra link field to each table position.
  • 7. hashing Analysis: • The worst case running time for insertion is O(1). • Deletion of an element x can be accomplished in O(1) time if the lists are doubly linked. • In the worst case behaviour of chain-hashing, all n keys hash to the same slot, creating a list of length n. The worst-case time for search is thus θ(n) plus the time to compute the hash function.
  • 8. A good hash function is one that minimizes collision and spreads the records uniformly throughout the table. that is why it is desirable to have larger array size than actual number of records. More formally, suppose we want to store a set of size n in a table of size m. The ratio α = n/m is called a load factor, that is, the average number of elements stored in a Table.
  • 9. Resolving Hash Collisions by Open Addressing • Simplest method of resolving the hash collision is to place record into the next available position in the array. • e.g. if key = 7803497. • Then using hash function h(key) = key% 1000 will produce 497. However if the 497th position is already occupied by key = 2885497, then next available position is chosen. • The above technique is termed as Linear probing. • the approach however a some pitfall called primary clustering problem.
  • 10. • Primary clustering: the phenomenon where two keys that hashes into different values compete with each other in successive rehashes. Primary clustering is the result of the formation of blocks of occupied positions.
  • 11. Eliminating primary clustering Solution 1: allow the rehash function to depend on the number of times the particular function is applied for hash value. Rh(I,j) yields I the hash value if the key is being rehashed for jth time. ist rehash yeilds rh1 = rh(h(key),1) 2nd rehash yeilds rh2 =rh(rh1 +2)%tablesize and so on. Solution 2: rather than always moving one spot, move i2 spots from the point of collision, where i is the number of attempts to resolve the collision. Ie. The rehash of h(key) will be (h(key)+ sqr(i))%table size. The method is called as Quadratic Rehash.
  • 12. Double Rehash • Both the solutions for eliminating the primary clustering suffers from another pitfall called secondary clustering. A phenomenon in which two keys hashes into same hash value then follows the same rehash path. • One way of eliminating all types of clustering is to use double hash technique, which uses two hash functions: h1(key) and h2(key). The h1(key) determines the location for insertion, if occupied, then rehash function rh(i+h2(key))%tablesize is successively used untill an empty location is found.

Editor's Notes

  1. Rafi dar