Pick the fix
You must check if each of a million incoming words is in a stored list of 50,000 words. Nothing else is needed. What should you use?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A A set of the stored words
Right: exact membership in O(L) with the least effort and memory.
When only exact lookups are needed, the simplest hashed structure wins; a trie earns its cost through prefix questions.
Why not the others?
- B A trie of the stored words. It works, but prefix features are unused and memory is higher.
- C Sort the stored words and scan from the start each time. Scanning is O(n) per word.