Data Structures & AlgorithmsModerateInfosys · Wipro pattern
Double hashing in a table of size 11 uses h1(k) = k mod 11 and h2(k) = 7 − (k mod 7); probe i goes to (h1 + i·h2) mod 11. Keys 14, 25, 36 are inserted in that order. In which slot does 36 end up?
- A. 4
- B. 9
- C. 5
- D. 1
Correct answer: B. 9
14 → 14 mod 11 = 3. 25 → 3 is taken; h2(25) = 7 − 4 = 3, so it goes to 6. 36 → 3 taken; h2(36) = 7 − 1 = 6: (3 + 6) mod 11 = 9, which is free. Linear probing would have put 36 at slot 4 and 25 at 4 as well; '5' uses the h2 of 25 for 36.
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 DISTINCT palindromic substrings (counted as strings, not by position) does 'abaab' have?
- For each element of [4, 10, 5, 8, 20, 15, 3, 12], find the nearest SMALLER element to its LEFT (−1 if none) using a monotonic stack. What…
- The numbers 1, 2, 3, 4, 5 are pushed onto a stack in that order, and pops may happen at any time. Which of these pop sequences is…
- Top-down merge sort (split until single elements, then merge) sorts an array of 13 elements. How many times is the merge step called?
- Insertion sort (shift larger elements right; one key comparison per inner-loop test) sorts [2, 4, 1, 3, 5] into ascending order. How many…
- Using a sliding window, what is the length of the longest contiguous subarray of [1, 2, 1, 3, 4, 3, 5, 3, 3] that contains at most 2…