Almost linear hash function
An almost linear function is a function h such that, for every inputs x and y, one of the following two equations hold:
- .
If equation 1 always holds, then h is a linear function. But if in some cases equation 2 holds, then h is almost linear.
The almost-linearity concept is mainly used with hash functions. A hash function can be used to map a large domain (e.g. the numbers between 0 and M − 1) to a much smaller domain (e.g. the numbers between 0 and m − 1, where m < M). It is easy to create a linear hash function, e.g. for every constant a, the following function is linear:
However, this family of functions is missing some other features that are required from a hash function, e.g. it is not universal. In contrast, the following function is both universal and almost linear, for every odd constant a and for every M, m which are powers of 2:[1][2]
where means integer division (taking only the integral part of the result and discarding the remainder).
For example, if M = 64, m = 16 and a = 1:
For every x, y:
Hence, if , then it is discarded in the integer division by 4, and we get:
The only other option is that . In this case, dividing it by 4 gives an integer part of 1, and we get:
This proves that h is an almost-linear function.
References
- ↑ Dietzfelbinger, M.; Hagerup, T.; Katajainen, J.; Penttonen, M. (1997). "A Reliable Randomized Algorithm for the Closest-Pair Problem". Journal of Algorithms 25: 19. doi:10.1006/jagm.1997.0873.
- ↑ Kopelowitz, Tsvi; Pettie, Seth; Porat, Ely (2014). "3SUM Hardness in (Dynamic) Data Structures". arXiv:1407.6756 [cs.DS].