- Quadratic probing
Quadratic probing is a scheme in
computer programming for resolving collisions inhash table s.Quadratic probing operates by taking the original hash value and adding successive values of an arbitrary
quadratic polynomial to the starting value. This algorithm is used in open-addressedhash table s. Quadratic probing provides good memory caching because it preserves somelocality of reference ; however,linear probing has greater locality and, thus, better cache performance. Quadratic probing better avoids the clustering problem that can occur with linear probing, although it is not immune.Quadratic probing is used in the
Berkeley Fast File System to allocate free blocks. The allocation routine chooses a new cylinder-group when the current is nearly full using quadratic probing, because of the speed it shows in finding unused cylinder-groups.Quadratic probing is a "classical" method to deal with collisions.A recent development to deal with collisions in
hash table s ina potentially more efficient manner iscuckoo hashing .Quadratic Probing Algorithm
Let be a
hash function that maps an element to an integer in , where is the size of the table.Let the th probe position for a value be given by the function , where . If , then degrades to a linear probe. For a given
hash table , the values of and remain constant.Example: If , then the probe sequence will be
For , a good choice for the constants are 1/2, as the values for in are all distinct. [Proof: assume there exist i,j such that i,j in and (i+i^2)/2 = (j+j^2)/2 mod m. Then i+i^2 = j+j^2 mod 2m, i^2-j^2 + i-j = 0 mod 2m, (i-j)(i+j) + (i-j) = 0 mod 2m, and (i-j)(i+j+1) = 0 mod 2m. Since 2m is a power of 2, and only one of the two factors can be even, we must have i-j = 0 mod 2m or i+j+1 = 0 mod 2m. The latter is not possible with i,j in , and the former implies that i=j. ] This leads to a probe sequence of where the values increase by .
For prime , most choices of and will make distinct for in . Such choices include 1/2, 1, and . Because there are only about m/2 distinct probes for a given element, it is difficult to guarantee that insertions will succeed when the load factor is > 1/2.
ee also
*
Hash tables
*Hash collision
*Double hashing
*Linear probing
*Hash function Notes
References
Wikimedia Foundation. 2010.