I am confused for the last few days in finding the difference between primary and secondary clustering in hash collision management topic in the textbook I am reading.
2 Answers
Primary Clustering
- Primary clustering is the tendency for a collision resolution scheme such as linear probing to create long runs of filled slots near the hash position of keys.
- If the primary hash index is
x
, subsequent probes go tox+1
,x+2
,x+3
and so on, this results in Primary Clustering. - Once the primary cluster forms, the bigger the cluster gets, the faster it grows. And it reduces the performance.
Secondary Clustering
- Secondary clustering is the tendency for a collision resolution scheme such as quadratic probing to create long runs of filled slots away from the hash position of keys.
- If the primary hash index is
x
, probes go tox+1
,x+4
,x+9
,x+16,
x+25
and so on, this results in Secondary Clustering. - Secondary clustering is less severe in terms of performance hit than primary clustering, and is an attempt to keep clusters from forming by using Quadratic Probing. The idea is to probe more widely separated cells, instead of those adjacent to the primary hash site.
-
10Were I to have ten more voting up right, I would do so. Apr 29, 2017 at 13:43
-
Primary clustering means that if there is a cluster and the initial position of a new record would fall anywhere in the cluster the cluster size increases. Linear probing leads to this type of clustering.
Secondary clustering is less severe, two records do only have the same collision chain if their initial position is the same. For example quadratic probing leads to this type of clustering.
-
10I would like to add a clarification, (just in case the language of the answer created doubt). Secondary clustering happens in both Linear probing as well as Quadratic Probing, i.e. linear probing also suffers from secondary clustering. Mar 28, 2016 at 17:08