Implementation of a simple Prefix Trie in Python. It allows for insertion, search, and checks if a string in the Trie starts with a prefix.
The program was created with Python3.
To use this Trie, import the Trie class by adding:
from trie import Trie
to the top of your python file.
Then, you can create a Trie using the constructor trie = Trie()
Methods:
insert(word) - Inserts word into Trie
search(word) - Returns if word is in Trie
starts_with(prefix) - Returns if a word in Trie starts with prefix\
To insert, run trie.insert("word")
To search, run trie.search("word")
To check if the trie contains a prefix, run trie.starts_with("w")
Credits to LeetCode problem: https://leetcode.com/problems/implement-trie-prefix-tree/description/