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?
- A. Direct indexing works in O(1) with about 4 MB of memory and needs no hashing
- B. Direct indexing fails because array indices must be prime
- C. Direct indexing needs a hash function to be correct
- 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
- 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?
- How many disk moves does the optimal Tower of Hanoi solution need for 5 disks?
- How many binary strings of length 4 contain at least two adjacent 1s?
- How many subsets of {1, 2, ..., 10} have an even sum of elements? The empty set counts.