🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Tries (Prefix Trees): questions with answers

15 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. What does the end-of-word flag in a trie node tell you?
  2. Q2. What does this print? (code)
  3. Q3. Words cat, car and cart are stored. What does search("ca") return?
  4. Q4. What is the time to insert a word of length L into a trie that already holds n words?
  5. Q5. Each node keeps a count of words passing through it. How do you answer "how many words start with p"?
  6. Q6. What does this print? (code)
  7. Q7. Why might you choose a 26-slot array per node instead of a hash map?
  8. Q8. For which task is a plain hash set as good as a trie?
  9. Q9. In "word search II" (find many dictionary words in a letter grid), why does a trie help?
  10. Q10. Ten words share the prefix "inter". How many times are the letters i-n-t-e-r stored in the trie?
  11. Q11. What does this print? (code)
  12. Q12. How does startsWith(prefix) differ from search(word) in a trie?
  13. Q13. What does this print? (code)
  14. Q14. Autocomplete in a trie: after walking down to the node for the typed prefix, how do you list the suggestions?
  15. Q15. What is the main memory drawback of a trie with a 26-slot array in every node?