ProgrammingModerate
A hash table with 2^20 slots holds 2 x 10^5 keys and uses a good hash. What is the expected cost of a successful lookup?
- A. About constant time, since the load factor is near 0.2
- B. About linear time, since every key collides
- C. About n^2 time for the whole set
- D. About log n with a sorted array
Correct answer: A. About constant time, since the load factor is near 0.2
A load factor of 0.2 keeps chains short, so the expected cost of a lookup is close to a constant.
More C Programming questions
- For n = 10^5, which expression correctly counts the pairs (i, j) with i < j where a[i] + a[j] equals a target, in O(n log n) time?
- A recursive function is called with depth 10^6 in C on a typical 8 MB stack with 64-byte frames. Is this safe?
- A bit set of 64 flags is packed in one unsigned long long. Which expression tests flag 17?
- What is the first printed value of this loop? for (int i = 3; i > 0; i--) printf("%d", i);
- int x = 0; while (x < 3) x = x + 1; printf("%d", x); What is printed?
- int count = 0; for (char c = 'a'; c <= 'z'; c++) if (c != 'e' && c != 'i' && c != 'o' && c != 'u') count++; printf("%d", count); What is…