Skip to content

Commit 7cd00a1

Browse files
committed
Started Trie implementation.
* Basic definition of Trie in comments at the top of the file * Defined Trie class and method signatures.
1 parent 89d48b5 commit 7cd00a1

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

data_structures/Trie/Trie.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
pass

data_structures/Trie/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)