We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 89d48b5 commit 7cd00a1Copy full SHA for 7cd00a1
data_structures/Trie/Trie.py
@@ -0,0 +1,21 @@
1
+'''
2
+A Trie/Prefix Tree is a kind of search tree used to provide quick lookup
3
+of words/patterns in a set of words. A basic Trie however has O(n^2) space complexity
4
+making it impractical in practice. It however provides O(max(search_string, length of longest word)) lookup
5
+time making it an optimal approach when space is not an issue.
6
7
+
8
9
+class TrieNode:
10
+ def __init__(self):
11
+ self.nodes = dict() # Mapping from char to TrieNode
12
13
+ def add_words(self, words: [str]):
14
+ for word in words:
15
+ self.add_word(word)
16
17
+ def add_word(self, word: str):
18
+ pass
19
20
+ def lookup_word(self, word: str) -> bool:
21
data_structures/Trie/__init__.py
0 commit comments