How does double hashing work




















The formula that will be used is:. The division method is generally a reasonable strategy, unless the key happens to have some undesirable properties. For example, if the table size is 10 and all of the keys end in zero. In this case, the choice of hash function and table size needs to be carefully considered. The best table sizes are prime numbers. One problem though is that keys are not always numeric. In fact, it's common for them to be strings.

One possible solution: add up the ASCII values of the characters in the string to get a numeric value and then perform the division method. The previous method is simple, but it is flawed if the table size is large. For example, assume a table size of and that all keys are eight or fewer characters long. However, this is not the case with quadratic probing unless you take care in the choosing of the table size. For example consider what would happen in the following situation:.

In order to guarantee that your quadratic probes will hit every single available spots eventually, your table size must meet these requirements:. Double Hashing is works on a similar idea to linear and quadratic probing. Use a big table and hash into it. In the computation above, the value of i will keep incrementing the offset will keep increasing until an empty slot is found.

Double hashing is useful if an application requires a smaller hash table since it effectively finds a free slot. Although the computational cost may be high, double hashing can find the next free slot faster than the linear probing approach.

View all Courses. All rights reserved. Courses Pricing. What is double hashing? Answer to 2nd part In double hashing, let the hash function be h k, i where k is the key and i is the probe sequence.

Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Explaining the semiconductor shortage, and how it might end. Does ES6 make JavaScript frameworks obsolete? Featured on Meta. Now live: A fully responsive profile. Related



0コメント

  • 1000 / 1000