ProgrammingModerate

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?

  1. A. Direct indexing works in O(1) with about 4 MB of memory and needs no hashing
  2. B. Direct indexing fails because array indices must be prime
  3. C. Direct indexing needs a hash function to be correct
  4. D. Direct indexing is O(N) per lookup because the array must be scanned

Correct answer: A. Direct indexing works in O(1) with about 4 MB of memory and needs no hashing

With keys bounded by about 10^6, a direct array of ints needs about 4 MB and gives O(1) access. Hashing is not required in that case.

More C Programming questions

Exams that ask this topic