Data Structures & AlgorithmsHardHCLTech · Wipro pattern
Keys 13, 28, 91, 42, 33 are inserted via linear probing (h(k) = k mod 7, probe by +1 on collision) into an initially empty table of size 7 (indices 0 to 6). What is the final table, left to right (_ = empty)?
- A. 13, 33, _, _, 42, 91, 28
- B. 28, 91, _, _, 42, 33, 13
- C. 28/91/42, _, _, _, _, 33, 13
- D. 28, 91, 42, _, _, 33, 13
Correct answer: D. 28, 91, 42, _, _, 33, 13
Each key goes to h(k) = k mod 7, and on a collision the next slot (wrapping around) is tried until an empty one is found. Simulating all insertions in order gives [28, 91, 42, _, _, 33, 13]. Using quadratic probing (+1², +2², ...) instead would give a different table, [28, 91, _, _, 42, 33, 13], since the probe sequence differs after the first collision.
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
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- A circular queue of capacity 4 starts empty and runs this sequence in order: enqueue(8), enqueue(2), enqueue(5), dequeue(), enqueue(1)…
- Binary search for first/last occurrence runs on the sorted array [1, 3, 7, 9, 11, 13, 15, 15, 16, 17, 18] for target 15. What (first…
- An LRU cache of capacity 3 runs this sequence of operations in order: put(8, 80), put(8, 80), put(6, 60), put(7, 70), put(8, 80), put(1…