ProgrammingHard
A table of size 5 uses h(k) = k % 5 with linear probing. Keys 15, 5, 10 and 3 are inserted in that order. How many slots are examined when searching for 15 afterwards?
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: B. 1
15 is inserted first and takes slot 0; 5 and 10 then probe on to slots 1 and 2, and 3 goes to slot 3. Searching for 15 finds it at slot 0, so one slot is examined.
More C Programming questions
- A hash table of size 5 uses h(k) = k mod 5 with linear probing. The keys 5, 10, 15 and 3 are inserted in that order into an empty table…
- A chained table has 4 buckets with h(k) = k % 4. Keys 1 and 5 are inserted with head insertion. Which key is first in bucket 1?
- A hash table starts with capacity 8 and doubles whenever the count exceeds half the capacity. After 9 insertions, what is the capacity?
- In a linear-probing table, slot 1 holds a tombstone and slot 2 holds key 6. A search for 6 begins at slot 1 (its hash). How many slots are…
- A singly linked list of five nodes 1 -> 2 -> 3 -> 4 -> 5 has the node with value 3 unlinked and freed. How many nodes remain?
- Deleting a node from the middle of a doubly linked list of length n costs what, if a pointer to the node is already known?