ProgrammingModerate
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. 1
- B. 9
- C. 5
- D. none, since they collide
Correct answer: C. 5
Both keys go to bucket 1. Head insertion puts the last inserted key first, so 5 comes before 1.
More C Programming questions
- 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?
- A chained table with 10 buckets holds 30 keys. What is the average chain length?
- A dynamic array grows from capacity 1 by doubling. How many doublings are needed to reach capacity 1024 from 1?