🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Design Search Autocomplete: all 10 questions

Quiz: Design Search Autocomplete · Question 1 of 10

Why store the top-k suggestions at every trie node?

Why store the top-k suggestions at every trie node?

  1. A.To save memory
  2. B.So a lookup only walks the prefix and returns a ready list, instead of searching the whole subtree
  3. C.Because tries cannot store full words
  4. D.To sort the alphabet
Answer & explanation

Correct answer: So a lookup only walks the prefix and returns a ready list, instead of searching the whole subtree

Precomputing the answer per prefix makes each lookup O(prefix length).

Can you get the rest right without peeking?

Take the timed Quiz: Design Search Autocomplete quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →