Data Structures & AlgorithmsModerateWipro · Accenture pattern

Keys 22, 33, 44, 55 go into a table of size 11 with quadratic probing h(k) + i² (mod 11). In which slots do they land, in order?

Keys 22, 33, 44, 55 go into a table of size 11 with quadratic probing h(k) + i² (mod 11). In which slots do they land, in order?
m = 11; t = [None] * m; slots = []
for k in (22, 33, 44, 55):
    h = k % m; i = 0
    while t[(h + i * i) % m] is not None: i += 1
    t[(h + i * i) % m] = k; slots.append((h + i * i) % m)
print(*slots)
  1. A. 0 1 4 9
  2. B. 0 1 2 3
  3. C. 0 1 3 6
  4. D. 0 2 4 6

Correct answer: A. 0 1 4 9

All four keys hash to 0. Quadratic probing tries offsets 0, 1, 4, 9: 22 → 0, 33 → 1, 44 → 4, 55 → 9. Linear probing would give 0, 1, 2, 3. Keys with the same home slot still follow the same sequence (secondary clustering).

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

Exams that ask this topic