Trie
A tree that stores strings by shared prefix, so each node represents a prefix all its descendants extend.
Trie (pronounced "try," from retrieval) stores a set of strings as a tree where each edge is labeled with a character and each node represents the prefix spelled out by the path from the root to it — so "car" and "cart" share every node up through "car," diverging only at the fourth character. A lookup, insert, or prefix check walks the tree one character at a time and costs time proportional to the string's length, not to how many strings are stored — a property no comparison-based structure shares (a Hash Table matches it, since hashing the key is also length-proportional, but tells you nothing about prefixes without a separate structure).
This is exactly why a trie is the standard structure behind autocomplete and typeahead: "give me every stored string starting with 'ca'" is a single walk down to the node for "ca," followed by a traversal of everything beneath it — a query a hash table cannot answer without scanning every key, since hashing deliberately destroys any relationship between similar keys' locations. A Bloom Filter answers a related but different question (is this exact string probably in the set) with no support for prefixes at all; the two are not substitutes for each other.
The cost is space: a naive trie allocates a node per character per branch, and a large alphabet (Unicode rather than lowercase ASCII) multiplies that overhead by the branching factor at every node. Two common fixes are used depending on which side of that trade-off matters more: a compressed trie (radix tree / Patricia trie) collapses runs of single-child nodes into one edge labeled with a whole substring, trading some lookup-time complexity for a large space reduction, while a plain array-of-26-children trie keeps lookups branch-free at the cost of the wasted array slots.
Tries also underlie IP routing tables (longest-prefix match over binary strings) and spell-checkers (walking off the beaten path measures edit distance from the nearest valid word) — anywhere "prefix" is the natural unit of comparison rather than "whole key."
See also7
B-Tree
A self-balancing tree with many children per node, designed to minimize the number of disk reads a lookup costs.
Computation & Algorithms8 connections
Big-O Notation
A coarse language for how an algorithm's cost grows as its input grows.
Computation & Algorithms21 connections
Iterator
An object that hands out the elements of a collection or sequence one at a time on request, separating how a sequence is produced from how it's consumed, which lets the same loop walk arrays, trees, files and infinite streams.
Computation & Algorithms7 connections
Lexical Analysis
The first stage of reading a program, which groups a stream of characters into tokens such as names, numbers, operators and keywords, usually using regular expressions compiled into a finite automaton, so the parser can work with words rather than letters.
Computation & Algorithms9 connections
Persistent Data Structure
Data structures that preserve every previous version when changed, sharing unchanged parts between versions so "copying" is cheap.
Computation & Algorithms9 connections
Subnet
A block of IP addresses that share a common prefix, written in CIDR notation such as 192.168.1.0/24, which decides what a device can reach directly and what it must send through a router.
Networks & Distribution13 connections
Autocomplete
Suggesting completions while someone types, which needs prefix-friendly indexes, ranking by likely intent, and careful handling of latency, typos, and accessibility.
Data & Content14 connections
Linked from9
- AutocompleteData & Content
Suggesting completions while someone types, which needs prefix-friendly indexes, ranking by likely intent, and careful handling of latency, typos, and accessibility.
- B-TreeComputation & Algorithms
A self-balancing tree with many children per node, designed to minimize the number of disk reads a lookup costs.
- Bloom FilterComputation & Algorithms
A probabilistic set membership structure that can say "definitely not present" but only "probably present."
- Lexical AnalysisComputation & Algorithms
The first stage of reading a program, which groups a stream of characters into tokens such as names, numbers, operators and keywords, usually using regular expressions compiled into a finite automaton, so the parser can work with words rather than letters.
- Persistent Data StructureComputation & Algorithms
Data structures that preserve every previous version when changed, sharing unchanged parts between versions so "copying" is cheap.
- Prompt CachingAgents & Language Models
Reusing the computed state of a prompt's unchanged prefix across requests, which only works if that prefix stays byte-identical.
- RecursionComputation & Algorithms
A function defined in terms of itself, solving a problem by solving smaller instances of the same problem.
- Regular ExpressionComputation & Algorithms
A pattern language for matching text, compiled internally into a finite state machine that runs over the input.
- SubnetNetworks & Distribution
A block of IP addresses that share a common prefix, written in CIDR notation such as 192.168.1.0/24, which decides what a device can reach directly and what it must send through a router.