HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, a family of
hash functions A hash function is any function that can be used to map data of arbitrary size to fixed-size values. The values returned by a hash function are called ''hash values'', ''hash codes'', ''digests'', or simply ''hashes''. The values are usually ...
is said to be ''k''-independent, ''k''-wise independent or ''k''-universal if selecting a function at random from the family guarantees that the hash codes of any designated ''k'' keys are
independent random variables Independent or Independents may refer to: Arts, entertainment, and media Artist groups * Independents (artist group), a group of modernist painters based in the New Hope, Pennsylvania, area of the United States during the early 1930s * Independe ...
(see precise mathematical definitions below). Such families allow good average case performance in randomized algorithms or data structures, even if the input data is chosen by an adversary. The trade-offs between the degree of independence and the efficiency of evaluating the hash function are well studied, and many ''k''-independent families have been proposed.


Background

The goal of hashing is usually to map keys from some large domain (universe) U into a smaller range, such as m bins (labelled = \). In the analysis of randomized algorithms and data structures, it is often desirable for the hash codes of various keys to "behave randomly". For instance, if the hash code of each key were an independent random choice in /math>, the number of keys per bin could be analyzed using the
Chernoff bound In probability theory, the Chernoff bound gives exponentially decreasing bounds on tail distributions of sums of independent random variables. Despite being named after Herman Chernoff, the author of the paper it first appeared in, the result is d ...
. A deterministic hash function cannot offer any such guarantee in an adversarial setting, as the adversary may choose the keys to be the precisely the
preimage In mathematics, the image of a function is the set of all output values it may produce. More generally, evaluating a given function f at each element of a given subset A of its domain produces a set, called the "image of A under (or through) ...
of a bin. Furthermore, a deterministic hash function does not allow for ''rehashing'': sometimes the input data turns out to be bad for the hash function (e.g. there are too many collisions), so one would like to change the hash function. The solution to these problems is to pick a function ''randomly'' from a large family of hash functions. The randomness in choosing the hash function can be used to guarantee some desired random behavior of the hash codes of any keys of interest. The first definition along these lines was
universal hashing In mathematics and computing, universal hashing (in a randomized algorithm or data structure) refers to selecting a hash function at random from a family of hash functions with a certain mathematical property (see definition below). This guarantees ...
, which guarantees a low collision probability for any two designated keys. The concept of k-independent hashing, introduced by Wegman and Carter in 1981, strengthens the guarantees of random behavior to families of k designated keys, and adds a guarantee on the uniform distribution of hash codes.


Definitions

The strictest definition, introduced by Wegman and Carter under the name "strongly universal_k hash family", is the following. A family of hash functions H=\ is k-independent if for any k distinct keys (x_1, \dots, x_k) \in U^k and any k hash codes (not necessarily distinct) (y_1, \dots, y_k) \in k, we have: : \Pr_ \left h(x_1)=y_1 \land \cdots \land h(x_k)=y_k \right= m^ This definition is equivalent to the following two conditions: # for any fixed x\in U, as h is drawn randomly from H, h(x) is uniformly distributed in /math>. # for any fixed, distinct keys x_1, \dots, x_k \in U, as h is drawn randomly from H, h(x_1), \dots, h(x_k) are independent random variables. Often it is inconvenient to achieve the perfect joint probability of m^ due to rounding issues. Following, one may define a (\mu, k)-independent family to satisfy: : \forall distinct (x_1, \dots, x_k) \in U^k and \forall (y_1, \dots, y_k) \in k, ~~\Pr_ \left h(x_1)=y_1 \land \cdots \land h(x_k)=y_k \right\le \mu / m^k Observe that, even if \mu is close to 1, h(x_i) are no longer independent random variables, which is often a problem in the analysis of randomized algorithms. Therefore, a more common alternative to dealing with rounding issues is to prove that the hash family is close in statistical distance to a k-independent family, which allows black-box use of the independence properties.


Techniques


Polynomials with random coefficients

The original technique for constructing -independent hash functions, given by Carter and Wegman, was to select a large prime number , choose random numbers modulo , and use these numbers as the coefficients of a
polynomial In mathematics, a polynomial is an expression consisting of indeterminates (also called variables) and coefficients, that involves only the operations of addition, subtraction, multiplication, and positive-integer powers of variables. An exampl ...
of degree whose values modulo are used as the value of the hash function. All polynomials of the given degree modulo are equally likely, and any polynomial is uniquely determined by any -tuple of argument-value pairs with distinct arguments, from which it follows that any -tuple of distinct arguments is equally likely to be mapped to any -tuple of hash values. In general the polynomial can be evaluated in any
finite field In mathematics, a finite field or Galois field (so-named in honor of Évariste Galois) is a field that contains a finite number of elements. As with any field, a finite field is a set on which the operations of multiplication, addition, subtr ...
. Besides the fields modulo prime, a popular choice is the field of size 2^n, which supports fast
finite field arithmetic In mathematics, finite field arithmetic is arithmetic in a finite field (a field containing a finite number of elements) contrary to arithmetic in a field with an infinite number of elements, like the field of rational numbers. There are infini ...
on modern computers. This was the approach taken by Daniel Lemire and Owen Kaser for CLHash.


Tabulation hashing

Tabulation hashing is a technique for mapping keys to hash values by partitioning each key into
byte The byte is a unit of digital information that most commonly consists of eight bits. Historically, the byte was the number of bits used to encode a single character of text in a computer and for this reason it is the smallest addressable uni ...
s, using each byte as the index into a table of random numbers (with a different table for each byte position), and combining the results of these table lookups by a bitwise
exclusive or Exclusive or or exclusive disjunction is a logical operation that is true if and only if its arguments differ (one is true, the other is false). It is symbolized by the prefix operator J and by the infix operators XOR ( or ), EOR, EXOR, , ...
operation. Thus, it requires more randomness in its initialization than the polynomial method, but avoids possibly-slow multiplication operations. It is 3-independent but not 4-independent. Variations of tabulation hashing can achieve higher degrees of independence by performing table lookups based on overlapping combinations of bits from the input key, or by applying simple tabulation hashing iteratively.


Independence needed by different types of collision resolution

The notion of ''k''-independence can be used to differentiate between different collision resolution in hashtables, according to the level of independence required to guarantee constant expected time per operation. For instance, hash chaining takes constant expected time even with a 2-independent family of hash functions, because the expected time to perform a search for a given key is bounded by the expected number of collisions that key is involved in. By linearity of expectation, this expected number equals the sum, over all other keys in the hash table, of the probability that the given key and the other key collide. Because the terms of this sum only involve probabilistic events involving two keys, 2-independence is sufficient to ensure that this sum has the same value that it would for a truly random hash function. Double hashing is another method of hashing that requires a low degree of independence. It is a form of open addressing that uses two hash functions: one to determine the start of a probe sequence, and the other to determine the step size between positions in the probe sequence. As long as both of these are 2-independent, this method gives constant expected time per operation. On the other hand,
linear probing Linear probing is a scheme in computer programming for resolving collisions in hash tables, data structures for maintaining a collection of key–value pairs and looking up the value associated with a given key. It was invented in 1954 by Gene ...
, a simpler form of open addressing where the step size is always one, requires 5-independence. It can be guaranteed to work in constant expected time per operation with a 5-independent hash function, and there exist 4-independent hash functions for which it takes logarithmic time per operation. For Cuckoo hashing the required k-independence is not known as of 2021. In 2009 it was shown that O(\log n)-independence suffices, and at least 6-independence is needed. Another approach is to use Tabulation hashing, which is not 6-independent, but was shown in 2012 to have other properties sufficient for Cuckoo hashing. A third approach from 2014 is to slightly modify the cuckoo hashtable with a so-called stash, which makes it possible to use nothing more than 2-independent hash functions.


Other Applications

Kane,
Nelson Nelson may refer to: Arts and entertainment * ''Nelson'' (1918 film), a historical film directed by Maurice Elvey * ''Nelson'' (1926 film), a historical film directed by Walter Summers * ''Nelson'' (opera), an opera by Lennox Berkeley to a lib ...
and David Woodruff improved the Flajolet–Martin algorithm for the Distinct Elements Problem in 2010. To give an \varepsilon approximation to the correct answer, they need a \tfrac-independent hash function. The
Count sketch Count sketch is a type of dimensionality reduction that is particularly efficient in statistics, machine learning and algorithms. It was invented by Moses Charikar, Kevin Chen and Martin Farach-Colton in an effort to speed up the AMS Sketch by ...
algorithm for
dimensionality reduction Dimensionality reduction, or dimension reduction, is the transformation of data from a high-dimensional space into a low-dimensional space so that the low-dimensional representation retains some meaningful properties of the original data, ideally ...
requires two hash functions, one 2-independent and one 4-independent. The Karloff–Zwick algorithm for the MAX-3SAT problem can be implemented with 3-independent random variables. The MinHash algorithm can be implemented using a \log\tfrac-independent hash function as was proven by Piotr Indyk in 1999Indyk, Piotr. "A small approximately min-wise independent family of hash functions." Journal of Algorithms 38.1 (2001): 84-90.


References


Further reading

* {{cite book , last1 = Motwani , first1 = Rajeev , last2 = Raghavan , first2 = Prabhakar , title = Randomized Algorithms , url = https://archive.org/details/randomizedalgori00motw_066 , url-access = limited , publisher = Cambridge University Press , year = 1995 , isbn = 978-0-521-47465-8 , page
221
Hash functions Search algorithms Error detection and correction