From 044afb8d21bda6017144cddc97fd795ab5206e29 Mon Sep 17 00:00:00 2001 From: bt3gl <138340846+bt3gl-cryptographer@users.noreply.github.com> Date: Tue, 8 Aug 2023 17:03:08 -0700 Subject: [PATCH] Update README.md --- tries/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tries/README.md b/tries/README.md index dec2d0c..81e478c 100644 --- a/tries/README.md +++ b/tries/README.md @@ -26,7 +26,7 @@ class Trie: def __init__(self): self.root = {} - def insert(self, word: str) -> None: + def insert(self, word: str)L node = self.root for c in word: if c not in node: @@ -58,6 +58,7 @@ class Trie:
* similar to a bst, when we insert a value to a trie, we need to decide which path to go depending on the target value we insert. + * the root node needs to be initialized before you insert strings. @@ -71,10 +72,13 @@ class Trie:
* all the descendants of a node have a common prefix of the string associated with that node, so it should be easy to search if there are any words in the trie that starts with the given prefix. + * we go down the tree depending on the given prefix, once we cannot find the child node, the search fails. + * we can also search for a specific word rather than a prefix, treating this word as a prefix and searching in the same way as above. + * if the search succeeds, we need to check if the target word is only a prefix of words in the trie or if it's exactly a word (for example, by adding a boolean flag).