Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
next up previous contents index

Fibonacci Hashing

The final variation of hashing to be considered here is called the Fibonacci hashing method  . In fact, Fibonacci hashing is exactly the multiplication hashing method discussed in the preceding section using a very special value for a. The value we choose is closely related to the number called the golden ratio.

The golden ratio  is defined as follows: Given two positive numbers x and y, the ratio tex2html_wrap_inline61318 is the golden ratio if the ratio of x to y is the same as that of x+y to x. The value of the golden ratio can be determined as follows:

eqnarray10536

There is an intimate relationship between the golden ratio and the Fibonacci numbers . In Section gif it was shown that the tex2html_wrap_inline57406 Fibonacci number is given by

displaymath61310

where tex2html_wrap_inline59432 and tex2html_wrap_inline59434!

The Fibonacci hashing method is essentially the multiplication hashing method in which the constant a is chosen as the integer that is relatively prime to W which is closest to tex2html_wrap_inline61338. The following table gives suitable values of a for various word sizes.

W tex2html_wrap_inline61344
tex2html_wrap_inline61346 40503
tex2html_wrap_inline61348 2654435769
tex2html_wrap_inline61350 11400714819323198485

Why is tex2html_wrap_inline61338 special? It has to do with what happens to consecutive keys when they are hashed using the multiplicative method. As shown in Figure gif, consecutive keys are spread out quite nicely. In fact, when we use tex2html_wrap_inline61344 to hash consecutive keys, the hash value for each subsequent key falls in between the two widest spaced hash values already computed. Furthermore, it is a property of the golden ratio, tex2html_wrap_inline61356, that each subsequent hash value divides the interval into which it falls according to the golden ratio!

   figure10565
Figure: Fibonacci hashing.


next up previous contents index

Bruno Copyright © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.