What is Trie Autocomplete?
Store words letter by letter so every word with a given prefix can be found quickly.
Type a tool name, format or task
Store words letter by letter so every word with a given prefix can be found quickly. Interactive step-by-step animation with JavaScript code, complexity and front-end use cases.
Loading animation...
Store words letter by letter so every word with a given prefix can be found quickly. Insert each word letter by letter, reusing existing nodes. Follow the typed prefix down the tree. Collect every word below that node as suggestions. Time complexity: O(prefix length + results). Space complexity: O(total letters). Search suggestions, command palettes, tag inputs and spell checkers.
Store words letter by letter so every word with a given prefix can be found quickly.
Time: O(prefix length + results). Space: O(total letters).
Search suggestions, command palettes, tag inputs and spell checkers.
No. This converter runs in your browser for ordinary use, so the input is not sent to a backend by this tool.
Keep working without searching again.
A trie stores words letter by letter, so words that share a prefix share a path. A star (*) marks the end of a word.
class Trie {constructor() { this.root = { children: {}, end: false }; }insert(word) {let node = this.root;for (const ch of word) {node = node.children[ch] ??= { children: {}, end: false };}node.end = true;}suggest(prefix) {let node = this.root;for (const ch of prefix) {node = node.children[ch];if (!node) return [];}return collect(node, prefix); // every node with end: true is a word}}
Tip: use the arrow keys to step and the space bar to play or pause.