In our open-address hash tables, we have used linear probing or double hashing. Another probing method, which
Question:
In our open-address hash tables, we have used linear probing or double hashing. Another probing method, which avoids some clustering, is called quadratic probing. The simplest version of quadratic probing works like this: Start by hashing the key to an array index. If there is a collision, then move to the next array index. If there is a second collision, then move forward two more spots through the array. After a third collision, move forward three more spots, and so on. For example, suppose a new key hashes to location 327 and this location is full. The next location we try is 328. If 328 is a second collision, then we move two spots forward to location 330. If 330 is a third collision, then we move three spots forward to location 333. If our calculation of the next spot takes us beyond the end of the array, then we “wrap around” to the front of the array (similar to double hashing). In general, if location i has just caused a collision and we have already examined count elements, then we increase i according to the assignment:
i = (i + count) % data.length;
In this formula, the “% data.length” causes the “wraparound” to the front of the array. For this approach to work correctly, the capacity must be a power of 2, such as 210 = 1024. Otherwise, the sequence of probes does not correctly examine all array items.
For this project, use quadratic hashing to reimplement the hash table from Figure 11.5 on page 592.
Step by Step Answer: