Data Structures & AlgorithmsHardProduct-company MCQ pattern
Keys 88, 61, 14, 52, 18 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. 18, 61, 88, 52, _, _, 14
- B. 14, 18, _, 52, 88, 61, _
- C. 14, _, _, 52, 88, 61, 18
- D. 14, _, _, 52, 88/18, 61, _
Correct answer: C. 14, _, _, 52, 88, 61, 18
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 [14, _, _, 52, 88, 61, 18]. Using quadratic probing (+1², +2², ...) instead would give a different table, [14, 18, _, 52, 88, 61, _], 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
- What is the postfix (Reverse Polish) form of the infix expression "j + g h -(i + c)", built with the standard stack-based conversion (^…
- The Dutch National Flag algorithm (single pass, three pointers low/mid/high) partitions [2, 2, 1, 0, 0, 0, 2, 2] (values 0, 1, 2 only) in…
- Two sorted linked lists [1 → 10 → 11 → 19 → 28] and [12 → 14 → 18 → 27 → 35] are merged with the standard O(n+m) two-pointer merge (always…
- Two sorted linked lists [3 → 14 → 35 → 39] and [9 → 20 → 21 → 27 → 34] are merged with the standard O(n+m) two-pointer merge (always take…
- Floyd's cycle detection runs on a linked list 1 → 2 → ... → 7 whose last node's next pointer points back to node 5 (0-based position 4)…
- Heights [1, 6, 2, 6, 2, 5, 2, 2, 7] represent vertical lines at each index. What is the maximum water area (min(height) × horizontal…