AiTechWorlds
AiTechWorlds
Insert and search words in a trie with shared-prefix nodes, end-of-word markers, and an animated search path.
class Trie:
def __init__(self):
self.children = {}
self.end = False
def insert(self, word):
cur = self
for ch in word:
cur = cur.children.setdefault(ch, Trie())
cur.end = TrueA trie (prefix tree) stores strings character by character along paths from the root. Words that share a prefix share nodes, making prefix lookups and autocomplete very fast. Insert and search take O(L) time, where L is the word length, independent of how many words are stored.
| Insert / Search | O(L) |
| Prefix query | O(L) |
| Space | O(total chars) |
The Trie Visualizer lets you insert and search words in a prefix tree and see how words sharing a prefix share nodes. A trie stores strings character by character along paths from the root, with end-of-word markers. Insert and search run in O(L) time, where L is the word length, independent of the number of stored words — which makes tries ideal for autocomplete and prefix queries.
Insert words
Type a lowercase word and click Insert; shared prefixes reuse existing nodes.
Search a word
Type a word and click Search to animate the path and see if it is a full word or only a prefix.
Inspect the structure
Green nodes mark the end of a word; the search path highlights in yellow.
Read the code
See the trie class in C++, Java, Python, or JavaScript and copy it.
100% Private — No Server Required
All processing happens directly in your browser. No data is uploaded, stored, or transmitted to any server.
Last reviewed on June 14, 2026 by the AiTechWorlds Tools Team. All processing runs locally in your browser.