Data Structures & AlgorithmsHardProduct-company MCQ pattern
Keys 12, 22, 32 are inserted into a size-10 table with h(k) = k mod 10 and linear probing. Then 22 is deleted by simply setting its slot back to EMPTY. What happens when we now search for 32?
- A. The search stops at the empty slot 3 and wrongly reports 32 as absent
- B. The search loops forever
- C. 32 is found at slot 3 because the deletion shifted it
- D. 32 is found at slot 4 after 3 probes
Correct answer: A. The search stops at the empty slot 3 and wrongly reports 32 as absent
12 → 2, 22 → 3, 32 → 4. Search for 32 starts at 2, then hits slot 3, which is now EMPTY, and stops: false 'not found'. That is why open addressing uses a DELETED (tombstone) marker or rehashes the cluster.
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
- 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…
- 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…