ProgrammingModerate
A hash table stores pointers to nodes allocated with malloc. What must happen when the table is destroyed?
- A. Only the bucket array must be freed, since free on it releases nodes too
- B. Nothing, because the table owns no memory
- C. Each node is freed by calling free on the bucket index
- D. Every node must be freed exactly once, and the bucket array freed too
Correct answer: D. Every node must be freed exactly once, and the bucket array freed too
Each malloc'd node is owned by the table, so each must be freed once. The bucket array is a separate allocation and needs its own free.
More C Programming questions
- The expected number of probes for an unsuccessful search in linear probing with load factor a = 0.9 is about what?
- For a hash map of N = 10^5 entries with 10^5 lookups, which implementation is correct and fast enough in C?
- A chained table has a load factor of 3. A successful search compares the key against nodes until it is found. What is the expected number…
- Keys are stored with h(k) = k % 10 in a chained table. Which key set gives the longest single chain for five keys?
- A table keeps keys as ints in an array of size 2^20 indexed directly by the key. Keys are at most 10^6. Which statement is correct?
- uint32t x = 0u; x = 1103515245u x + 12345u; is applied twice in a row, starting from x = 0. What is x after the second update, computed…