🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Tries (Prefix Trees): all 15 questions

Quiz: Tries (Prefix Trees) · Question 5 of 15

Each node keeps a count of words passing through it. How do you answer "how many words start with p"?

Each node keeps a count of words passing through it. How do you answer "how many words start with p"?

  1. A.Count all end flags in the whole trie
  2. B.Walk down the letters of p and return that node's count (0 if the path breaks)
  3. C.Return the count stored at the root
  4. D.Run a BFS from the root
Answer & explanation

Correct answer: Walk down the letters of p and return that node's count (0 if the path breaks)

The count at the prefix node is the number of words below it, found in O(length of p).

Can you get the rest right without peeking?

Take the timed Quiz: Tries (Prefix Trees) quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →