Consider the following hash table where the elements with the same hash value are inserted using linear probing. i.e. the keys \(e\) with the same hash value \(v\) are sorted in ascending order starting from \(v\) in a circular manner.

\begin{array}{ |c | c | c| c| c| c|c | c | c | c| c| c| c|c| } \hline
index & 0 &1 &2 &3 &4& 5& 6 &7 &8 &9 &10 &11 &12 \\ \hline
e& & aa & jj & & & & dd & & & ee & ff & gg& hh \\ \hline
v=H(e)& & 1 & 1 & & & & 6 & & & 9 & 10 & 9 & 9 \\ \hline
\end{array}

  1. Write the necessary declarations of the above data structure.
  2. Trace the insertion of the keys \(mm\), \(nn\), \(pp\) and \(ii\) (in that order) with hash values \(H(mm) = 4\), \(H(nn) =11\), \(H(pp) = 9\) and \(H(ii) = 9\) to the above hash table.
  3. Write a function that takes as input a key \(x\) and a hash table \(H\) and inserts \(x\) in the hash table \(H\) using the above approach.

Difficulty level
This exercise is mostly suitable for students
No solution

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Sorting using the radix sort algorithm