ProgrammingVery hard
A table of size 10 uses linear probing. Keys 5, 15 and 25 are inserted in that order with h(k) = k % 10. How many slots are examined in total during the three inserts?
- A. 3
- B. 5
- C. 6
- D. 9
Correct answer: C. 6
Count every slot looked at, including the one finally used: 5 checks 1 slot, 15 checks slots 5 and 6, and 25 checks 5, 6 and 7, so 1 + 2 + 3 = 6. 3 counts only the occupied slots that caused collisions, and 9 adds a phantom extra probe per insert.
More C Programming questions
- A quadratic probing table of size 8 starts at h = 2 and uses probe i checks (h + ii) % 8 for i = 0, 1, 2, 3. What index is checked at i = 2?
- A djb2-style string hash starts with h = 5381 and for each character computes h = h 33 + c (unsigned 32-bit wrap). What is the hash of "ab"?
- Which expression always gives a valid bucket index in the range 0 to m - 1 for a signed int key k, with m > 0?
- A chained hash table is resized by doubling whenever it becomes full, starting at capacity 1. Inserting 8 keys, how many element moves…
- Keys 8, 16, 24 and 32 are hashed with h(k) = k % 8 and then with h(k) = k % 7. Which statement is correct?
- With 10^5 keys and a load factor of at most 0.5, what is the smallest power-of-two table size that works?