A reached node is not always a word
transcript
A shop keeps a book of words. A search uses dots as wildcards. A dot matches any one letter. Count the words that match.
The book holds only cart. The pattern car reaches a node. But car is only a prefix. The right count is zero. Counting nodes would count every prefix.
When you add a word, mark its last node. When you count, check that mark. Prefixes of longer words stay unmarked.
A dot follows every child. The trie of five words has ten nodes. Only three words match c dot t.
To drop a word, clear its flag. Keep the nodes, as other words may use them. Longer words below it stay.
At each reached node, ask one question. Is a word marked here, or only a prefix? Count only the marked nodes.
A reached node may be a prefix. Ask the end flag before you count. Full breakdown in the lecture.