data_structures.trie.trie

A Trie/Prefix Tree is a kind of search tree used to provide quick lookup of words/patterns in a set of words. A basic Trie however has O(n^2) space complexity making it impractical in practice. It however provides O(max(search_string, length of longest word)) lookup time making it an optimal approach when space is not an issue.

Classes

TrieNode

Functions

main(→ None)

print_results(→ None)

print_words(→ None)

Prints all the words in a Trie

pytests(→ None)

test_trie(→ bool)

Module Contents

class data_structures.trie.trie.TrieNode
delete(word: str) None

Deletes a word in a Trie :param word: word to delete :return: None

find(word: str) bool

Tries to find word in a Trie :param word: word to look for :return: Returns True if word is found, False otherwise

insert(word: str) None

Inserts a word into the Trie :param word: word to be inserted :return: None

insert_many(words: list[str]) None

Inserts a list of words into the Trie :param words: list of string words :return: None

is_leaf = False
nodes: dict[str, TrieNode]
data_structures.trie.trie.main() None
>>> pytests()
data_structures.trie.trie.print_results(msg: str, passes: bool) None
data_structures.trie.trie.print_words(node: TrieNode, word: str) None

Prints all the words in a Trie :param node: root node of Trie :param word: Word variable should be empty at start :return: None

data_structures.trie.trie.pytests() None
data_structures.trie.trie.test_trie() bool
Morty Proxy This is a proxified and sanitized view of the page, visit original site.