Questions: Tries (Prefix Trees)

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A trie stores 1,000,000 words from a dictionary. How long does it take to look up whether the word 'algorithm' (10 characters) is present?

AO(1,000,000) — the query must be compared against all stored words
BO(log 1,000,000) ≈ O(20) — binary search over sorted dictionary entries
CO(10) — one edge traversal per character in the query string
DO(10 × 1,000,000) — each character must be checked against all stored strings
Question 2 Multiple Choice

Why are tries better than hash sets for autocomplete functionality?

ATries guarantee O(1) lookup while hash sets are O(m) for string keys
BTries store words in sorted alphabetical order, enabling binary search on suggestions
CTries support prefix queries natively — navigating to a prefix node puts you at the root of all matching completions
DTries use less memory than hash sets for large vocabularies with long strings
Question 3 True / False

A trie storing 10,000 words is slower to search than a trie storing 100 words, assuming the query string is the same length.

TTrue
FFalse
Question 4 True / False

In a trie, most node reachable from the root represents a complete stored word.

TTrue
FFalse
Question 5 Short Answer

Why does a trie consume more memory than a hash set when stored strings share few common prefixes, and when does the trade-off reverse?

Think about your answer, then reveal below.