ProgrammingHard
For a hash map of N = 10^5 entries with 10^5 lookups, which implementation is correct and fast enough in C?
- A. A linked list scanned fully per lookup, about 10^10 steps
- B. A chained table with a table size of about 2 x 10^5 buckets and expected O(1) lookups
- C. Sorting the entries before each lookup, about 10^10 steps
- D. A plain array scanned from the start per lookup, about 10^10 steps
Correct answer: B. A chained table with a table size of about 2 x 10^5 buckets and expected O(1) lookups
Expected O(1) lookups give about 10^5 operations in total. Full scans make 10^10 comparisons in the worst case, which is too slow.
More C Programming questions
- 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…
- How many permutations of 4 distinct items have no item in its original position?
- How many distinct strings can be formed by arranging the letters of AABB?