Data Structures & AlgorithmsVery hardProduct-company MCQ pattern
Keys 18, 41, 22, 44, 59, 32, 31, 96 are inserted in that order into a table of size 13 by double hashing: h₁(k) = k mod 13, h₂(k) = 7 − (k mod 7), probe i at (h₁ + i·h₂) mod 13. At which index is 96 stored?
- A. 0
- B. 11
- C. 12
- D. 8
Correct answer: B. 11
Before 96 the table holds 31→0, 41→2, 18→5, 32→6, 59→7, 22→9, 44→10 (44 and 31 collided at 5). For 96, h₁ = 5 and h₂ = 7 − 5 = 2, so it tries 5, 7, 9 (all full) and lands at 11. Linear probing from 5 would have stopped at 8.
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
- 1, 2, 3, 4 are pushed onto a stack in this order, with pops allowed at any time. How many of the 24 permutations can be produced as the…
- A queue uses two stacks: enqueue pushes onto IN; dequeue pops from OUT, first moving ALL of IN into OUT only if OUT is empty. For enq 1…
- What is the postfix form of (A + B) C − (D − E) (F + G)?
- What is the value of the prefix expression − + 2 3 4 / 8 2 ?
- Infix A (B + C (D − E)) / F is converted to postfix with an operator stack (operators and '(' are pushed onto it). What is the largest…
- Using a sliding window, find the length of the longest substring with no repeated character in the string dvdfabcda.