Read the table size m, the number of keys n, and then n integer keys. Insert the keys in order into an empty hash table of size m using h(k) = Math.floorMod(k, m) and linear probing (h(k), h(k)+1, … wrapping round to 0).
- If a key is already in the table, print
Duplicate: Kand skip it. - If all m slots are examined without finding a free one, print
Table full: K not inserted.
Then print every slot as [i] key, or [i] - for an empty slot, followed by the total number of collisions (occupied slots skipped while inserting the keys that were stored) and the load as size/m.
Input:
11 6 22 35 13 46 57 24
Output:
[0] 22
[1] -
[2] 35
[3] 13
[4] 46
[5] 57
[6] 24
[7] -
[8] -
[9] -
[10] -
Collisions: 10
Load: 6/11