ProgrammingHard

For a hash map of N = 10^5 entries with 10^5 lookups, which implementation is correct and fast enough in C?

  1. A. A linked list scanned fully per lookup, about 10^10 steps
  2. B. A chained table with a table size of about 2 x 10^5 buckets and expected O(1) lookups
  3. C. Sorting the entries before each lookup, about 10^10 steps
  4. 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

Exams that ask this topic