Data Structures & AlgorithmsModerateInfosys · Hashing
Keys 12, 22, 32, 13, 23 are inserted in this order into an empty hash table of size 10 using h(k) = k mod 10 and linear probing. At which index is 23 stored?
- A. 3
- B. 6
- C. 5
- D. 4
Correct answer: B. 6
12 -> 2, 22 -> 3, 32 -> 4, 13 -> 3 taken, 4 taken, so 5; 23 probes 3, 4, 5 (all taken) and lands at 6.
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
- A queue is built from two stacks: enqueue pushes on stack IN; dequeue pops from OUT, first moving all of IN onto OUT (one pop and one push…
- What is the minimum number of adjacent swaps needed to sort [3, 1, 2, 5, 4] in ascending order?
- For each element of [4, 5, 2, 25, 7, 8], take the first strictly greater element to its right (or -1 if there is none). What is the sum of…
- A sliding window of size 3 moves over [1, 3, -1, -3, 5, 3, 6, 7]. What is the sum of the window maximums?
- What is the length of the longest substring of "abcabcbbxyzab" with no repeated character?
- A singly linked list 1 -> 2 -> ... -> 7 is reversed in groups of k = 2; a final group with fewer than k nodes is left as it is. What is…