Data Structures & AlgorithmsModerateTCS NQT · Infosys pattern

Keys 50, 700, 76, 85, 92, 73, 101 are inserted into a hash table of size 7 with h(k) = k mod 7 and linear probing. What is the final table (slots 0–6)?

Keys 50, 700, 76, 85, 92, 73, 101 are inserted into a hash table of size 7 with h(k) = k mod 7 and linear probing. What is the final table (slots 0–6)?
m = 7; t = [None] * m
for k in (50, 700, 76, 85, 92, 73, 101):
    i = k % m
    while t[i] is not None: i = (i + 1) % m
    t[i] = k
print(" ".join("-" if x is None else str(x) for x in t))
  1. A. 700 50 85 73 101 92 76
  2. B. 700 50 92 85 73 101 76
  3. C. 700 85 50 92 73 101 76
  4. D. 700 50 85 92 73 101 76

Correct answer: D. 700 50 85 92 73 101 76

Home slots: 50→1, 700→0, 76→6, 85→1 (taken) →2, 92→1 →2 →3, 73→3 →4, 101→3 →4 →5. Primary clustering makes later keys walk past the growing cluster at slots 0–5.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic