← 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?
- A.startsWith also checks the end-of-word flag
- B.startsWith only needs the path for the prefix to exist; search also needs the end-of-word flag at the last node
- C.They are the same function
- 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 →