Data Structures & AlgorithmsVery hardAmazon · Microsoft OA

Problem: Insert keys into a hash table of size 7 with open addressing and LINEAR probing, h(k) = k mod 7.

Problem: Insert keys into a hash table of size 7 with open addressing and LINEAR probing, h(k) = k mod 7.
T = [None] * 7
for k in [50, 700, 76, 85, 92, 73, 101]:
    i = k % 7
    while T[i] is not None: i = (i + 1) % 7
    T[i] = k
print(T)
What is printed?
  1. A. [700, 50, 85, 92, 73, 101, 76]
  2. B. [700, 50, 85, 73, 101, 92, 76]
  3. C. [73, 50, 85, 92, 101, 700, 76]
  4. D. [700, 50, 92, 85, 73, 101, 76]

Correct answer: A. [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 probe longer and longer runs.

More Coding Interview Problems questions

Exams that ask this topic