Data Structures & AlgorithmsHardGATE CS · TCS NQT
A hash table of size 11 uses h(k) = k mod 11 with linear probing. Keys 5, 16, 27 and 38 are inserted in this order, and then key 16 is deleted by simply marking its slot empty (no tombstone). A standard search stops at the first empty slot. Which of the keys 5, 27 and 38 can still be found?
- A. All three
- B. 5 and 27
- C. None of the three
- D. Only 5
Correct answer: D. Only 5
All four keys hash to slot 5 and occupy slots 5, 6, 7 and 8. After slot 6 is emptied, searches for 27 and 38 stop at slot 6 and fail; only 5, found at its home slot, is still reachable, which is why deletions need tombstones.
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
- For the array [1, 3, -1, -3, 5, 3, 6, 7, 2, 9], consider every window of 4 consecutive elements. The sum of the maximum of each window is:
- A circular queue uses an array of size 5 with the convention that front is the index of the next element to dequeue, rear is the index of…
- The integers 1, 2, 3, 4, 5, 6 are pushed onto an initially empty stack in this order; pops may happen at any time, and the 6 popped values…
- A hash table of size 11 uses double hashing: the probe sequence for key k is (k mod 11 + i · (7 − (k mod 7))) mod 11 for i = 0, 1, 2…
- A hash table of size 7 uses h(k) = k mod 7 with linear probing. A delete leaves a tombstone, an insert goes into the first empty or…
- A circular queue is stored in an array of size 6 (indices 0-5). Initially empty, front = 0, and an enqueue stores at index (front + count)…