Data Structures & AlgorithmsVery hardProduct company OA
20 keys are hashed independently and uniformly into 100 slots. What is the EXPECTED number of colliding pairs (unordered pairs of keys that land in the same slot)?
- A. 0.2
- B. 1.9
- C. 2.0
- D. 0.19
Correct answer: B. 1.9
There are C(20, 2) = 190 pairs and each collides with probability 1/100, so by linearity of expectation the expected count is 1.9. '2.0' uses 20²/2 instead of 20·19/2; '0.2' divides the number of keys by the number of slots, which is the load factor, not a collision count.
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
- How many contiguous subarrays of [1, 3, 2, 4, 6, 5] satisfy max − min ≤ 2? (Two monotonic deques shrink the window from the left.)
- What is the smallest positive integer missing from [3, 4, −1, 1, 7, 2, 2, 9]? (In-place cyclic placement: put each value v with 1 ≤ v ≤ n…
- Which problem CANNOT be solved by a plain variable-size sliding window that shrinks from the left?
- The Boyer–Moore majority vote (candidate/counter, no verification pass) runs on [3, 5, 5, 7, 7, 7, 7, 7, 3]. What candidate and final…
- KMP failure function (lps[i] = length of the longest proper prefix of p[0..i] that is also a suffix). What is printed? python def lps(p)…
- The array [1, 2, 3, 4, 5, 6, 7, 8] is rotated RIGHT by 3 positions and then LEFT by 2 positions. What is the final array?