ProgrammingVery hard
Keys 2, 7 and 12 are inserted into a table of size 5 with h(k) = k % 5 using linear probing. In which slot does 12 end up?
- A. 3
- B. 4
- C. 2
- D. 0
Correct answer: B. 4
2 takes slot 2, 7 hashes to slot 2 and probes to 3, and 12 hashes to slot 2, which is taken, then slot 3 is also taken, so it lands at slot 4.
More C Programming questions
- A chained hash table is searched for a key that is absent. The chain at its bucket has 4 nodes. How many key comparisons are made?
- A heap of 15 nodes stored as an array (complete binary tree) has what height, counting levels from 1?
- A singly linked list is searched for a value with a loop that stops when the value is found. For n nodes, what is the worst-case number of…
- A list with a sentinel head node is used to simplify insertion. What does the sentinel remove the need for?
- A circular buffer of capacity 4 holds 3 items and is written with 2 more. How many items are in it afterwards if the buffer overwrites the…
- A hash table with open addressing and a load factor of 0.9 is used. Why is this risky?