Suppose that we are given a key $k$ to search for in a hash table with positions $0, 1, \dots , m-1$, and suppose that we have a hash function $h$ mapping the key space into the set $\{0, 1, \dots , m-1 \}$. The search scheme is as follows:
- Compute the value $i \gets h(k)$, and set $j \gets 0$.
- Probe in position $i$ for the desired key $k$. If you find it, or if this position is empty, terminate the search.
- Set $j \gets (j + 1)\bmod{m}$ and $ i \gets (i+j)\bmod{m}$, and return to step 2.
Question: Show that this scheme is an instance of the general "quadratic probing" scheme by exhibiting the appropriate constants $c_1, c_2$ for the equation: $$h(k,i) = (h(k) + c_1i+c_2i^2) \bmod{m}, \text{ where } i=0,\dots, m-1$$ and $h(k) = k \bmod {m}$.
Attempt:
What we did here is to consider $j$ as a for loop and substitute in $i$:
$$i_0 = h(k), j_0 = 0$$
If we did not find the item and the termination case is not fulfilled, we probe:
$$i_1 = h(k) + j_0 = h(k), j_1 = j_0 + 1 = 1$$
If we did not find the item and the termination case is not fulfilled, we probe:
\begin{gather} i_2 = h(k) + j_1 = h(k) + 1, j_2 = j_1 + 1 = 2 \\ \vdots \\ i_i = h(k) + j_1 = h(k) + 1 + \cdots + (i-1), j_i = i \end{gather}
Problem: Now I realized that sequence $1 + \dots + (i-1)$ gives quadratic term, but it's not from $i=0, \dots, i$ so that I can sum all values as one term is missing, which is the $i$th term. What do you think please?
Problem 2: Prove that this algorithm examines every table position in the worst case. I would like to ask you here about general approach to solve this question not detailed solution. So, here it's sufficient as I understood to show that for two probing sequences, we won't end up in the same slot and that guarantees that we will examine every single slot in the hash table. Could you please explain if this approach sounds right for you and what would you propose in this case please?