Skip to content

Commit 0abd857

Browse files
authored
Update Trie_add_Search_using_dict.py
1 parent 41367d8 commit 0abd857

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

Trie/Trie_add_Search_using_dict.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
"""
2+
Purpose:
3+
4+
Implementation of Trie has been asked in my interviews like in Google
5+
Store word in Dictionary
6+
Search word in the dictionary returns True if exist
7+
Stores words in a compressed manner
8+
"""
9+
"""
210
Inputs:
311
1nd line no of word you want to store in Trie (int)
412
2rd line to (2+1st line input)th line (string)
@@ -43,9 +51,24 @@ def search(self,word): # This function searches whether the word is presant or n
4351
checks.append(input())
4452

4553

46-
dictionary = Trie()
54+
55+
"""
56+
Time complexity :
57+
Insert: O(word Length)
58+
Search: O(word Length)
59+
60+
Space complexity :
61+
Insert: O(1)
62+
Search: O(1)
63+
64+
Storages required for storing words:
65+
if no word has same prefix the required (total word length+1)*(char size)
66+
67+
"""
68+
dictionary = Trie() # Trie object created
69+
4770

4871
for k in words:
49-
dictionary.add(k)
72+
dictionary.add(k) # adding word in Trie from words list
5073
for k in checks:
51-
print(dictionary.search(k))
74+
print(dictionary.search(k)) # printing Searched word results if present then prints True if not present then returns False

0 commit comments

Comments
 (0)