🎙 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 12 of 15

How does startsWith(prefix) differ from search(word) in a trie?

How does startsWith(prefix) differ from search(word) in a trie?

  1. A.startsWith also checks the end-of-word flag
  2. B.startsWith only needs the path for the prefix to exist; search also needs the end-of-word flag at the last node
  3. C.They are the same function
  4. D.startsWith scans every word in the trie
Answer & explanation

Correct answer: startsWith only needs the path for the prefix to exist; search also needs the end-of-word flag at the last node

"ca" is a valid prefix of "cat" even though "ca" itself was never inserted as a word.

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 →