Trie Visualizer
A tree used to store strings and efficiently search prefixes, such as dictionary words. Insert words, search, delete, and list every word for a prefix, with each character step explained.
How to use the Trie Visualizer on KickSolve
Three quick steps, no account needed.
About the Trie Visualizer on KickSolve
What it is and how it works.
What is a trie?
A trie, or prefix tree, stores strings character by character. Each node is one character and the path from the root spells a prefix. A marker shows which nodes end a complete word.
Key properties
- Insert, search and delete take O(L) for a word of length L, independent of how many words are stored
- Words with a common prefix share the same nodes
- A prefix query finds all matching words from one subtree
- Words come out in alphabetical order by walking children in order
Real-world uses
- Autocomplete and search suggestions
- Spell checkers and dictionaries
- IP routing tables (binary tries)
- Phone keypad predictive text
Comparing trees? Try the AVL Tree, Red-Black Tree, B-Tree or B+ Tree visualizer.
Trie cases at a glance
The situations the step-by-step log will name for you.
| Operation | What happens | Time |
|---|---|---|
| Insert | Follow or create one node per character, then mark the end of the word | O(L) |
| Search word | Follow every character, then check the end-of-word marker | O(L) |
| Prefix search | Follow the prefix, then collect all words in the subtree | O(L + k) |
| Delete | Unmark the end, then remove nodes that have no children and end no other word | O(L) |
Worked example
The same steps the visualizer animates for any input.
Insert "cat": creates c, a, t. The t node is marked as a word end. Insert "car": reuses c and a, creates r. Marked as a word end. Insert "dog": creates d, o, g. 9 characters stored in 7 nodes, because "ca" is shared. Prefix "ca": cat, car (the subtree under a).
Trie FAQ
Quick answers.
What is a trie?
A tree for storing strings where each node is a character and each path from the root is a prefix. Also called a prefix tree.
What does the green double ring mean?
It marks a node where a complete stored word ends.
Why is a trie good for autocomplete?
Follow the typed prefix once, then every word in that subtree is a suggestion.
What is the time complexity of a trie?
Insert, search and delete are O(L), where L is the length of the word.
Trie vs hash table?
A hash table finds exact words fast. A trie also supports prefix queries and ordered output.
How does trie deletion work?
Remove the end marker, then delete nodes upward while they have no children and do not end another word.
What is the downside of a trie?
It can use a lot of memory when words share few prefixes, since each character needs a node.
Is the visualizer free and private?
Yes. Free, no signup, and everything runs in your browser.
More free tools from KickSolve
Other tree visualizers.