Skip to main content
←Architecture WorkspaceArchOSWorkspaces/
Sign in
ALGORITHM CANVAS · TRIE / RADIX TREE · TIME O(L) · SPACE O(Σ · N)
Prefix Trie & Longest-Prefix Autocomplete
Share common character prefixes along tree edges so lookup and autocomplete scale with key length L rather than dictionary size N.
NODES TREE (3 ACTIVE NODES)rootrra
STEP 1/4 · L9
nodes=["root","r","ra"]inserted=["ra"]
PYTHON 3.12 · INSTANT PREVIEW
1def build_trie_trace(words):
2 nodes = ["root"]
3 inserted = []
4 for w in words:
5 prefix = ""
6 for ch in w:
7 prefix += ch
8 if prefix not in nodes:
9 nodes.append(prefix)
10 inserted.append(w)
11 return nodes