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)- A. 0 1 4 9
- B. 0 1 2 3
- C. 0 1 3 6
- 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).
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is printed? (stack-based reversal of words) python s = "data structures are fun" st = [] for w in s.split(): st.append(w) out = []…
- Convert the infix expression to postfix (^ is right-associative, higher than and /, which are higher than + and −). What is printed?…
- Evaluate the postfix expression with single-digit operands. What is printed? python st = [] for t in "62/3-42+": if t.isdigit()…
- What is printed? (deque operations) python from collections import deque d = deque([1, 2, 3]) d.appendleft(0); d.append(4) d.rotate(2)…
- What is printed? (singly linked list, delete every node whose value equals x) python class N: def init(s, v, n=None): s.v, s.n = v, n h =…
- What is printed? (finding the intersection node of two linked lists by switching heads) python class N: def init(s, v, n=None): s.v, s.n =…