Searching checks if the complete path exists and ends at a word:
def search(word):
node = root
for char in word:
if char not in node.children:
return false
node = node.children[char]
return node.isEndOfWord
If any character is missing, the word doesn't exist. if you reach the end but isEndOfWord is false, the path exists as a prefix of some other word, but the word itself isn't in the trie.
Example: trie contains "card". Search for "car" follows c→a→r, but isEndOfWord is false (only "card" ends at d). Search returns false.
Time: where is word length.