Systematic designAdvanced

Autocomplete for a search box

Scenario

Design the data structure behind a search box that, after each keystroke, shows the 10 most popular completions of the current prefix. The dictionary has 10⁷ terms with popularity counts; queries arrive at 10⁴ per second; popularity counts change over time. Cover the core structure, top-k retrieval, memory, updates and caching.

Your task

  1. Clarify: latency budget per keystroke, whether ranking is global popularity or personalized, how fresh updates must be, alphabet size.
  2. Choose the core structure for prefix lookup and explain the alternatives (sorted array + binary search, hash map of prefixes).
  3. Design top-10 retrieval: naive subtree walk vs precomputed per-node top-k. Discuss the cost of each and how updates interact with precomputation.
  4. Estimate memory for 10⁷ terms and propose reductions.
  5. Add caching and describe how invalidation works.
Systematic ReasoningCommunicationComplexity AnalysisProblem Clarification

Work it out

Write your analysis before revealing anything. The self-check below compares it against what a strong answer contains.

Reveal

Progressive — each section builds on the previous one.

Key observation
The fix
Edge cases
Complexity
What this tests

Self-check

Tick what your analysis covered. Be honest — this feeds your readiness profile.

0/8

Related concepts