Skip to content

Resource · Guide or article

Trie

Explains the prefix tree, where a node's position encodes its key and every descendant shares that node's prefix, which suits string-keyed lookups.

Reviewed

Open the original: Trie (opens the original site in a new tab)

Practice this topicOpens the practice interviewer with a question on Trees.

Add to a roadmap

Keep this resource with a roadmap you follow. It appears as your own extra resource; the roadmap's steps don't change and it doesn't count toward your tracked steps.

Source content: English

Read this in other languages: 简体中文, Русский, Português, Українська, 한국어 In computer science, a trie, also called digital tree and sometimes radix tree or prefix tree (as they can be searched by prefixes), is a kind of search tree—an ordered tree data structure that is used to store a dynamic set or associative array where the keys are usually strings. Unlike a binary search tree, no node in the tree stores the key associated with that node; instead, its position in the tree defines the key with which it is associated. All the descendants of a node have a common prefix of the string associated with that node, and the root is associated with the empty string. Values are not necessarily associated with every node. Rather, values tend only to be associated with leaves, and with some inner nodes that correspond to keys of interest. For the space-optimized presentation of prefix tree, see compact prefix tree.

PrepKit overview

PrepKit editors wrote and reviewed this overview from the source repository. It is not text from the resource itself.

Suited to
The source does not state a level
Format
Reference

What it covers

  • How tries differ from binary search trees in where keys are stored
  • Root as the empty string, values held at leaves and selected inner nodes, and a pointer to compact prefix trees

How to use it

PrepKit study advice, not a claim made by the source.

Implement insert, search and startsWith, then use the trie to return every stored word sharing a given prefix.

Scope and limitations

No operations, complexity or autocomplete example on the page; implementation detail is left to the Wikipedia and YouTube links.

Access and format

Short README on GitHub, trekhleb/javascript-algorithms (MIT), with five translations linked. English, free.

Reviewed by PrepKit on Oct 2, 2026. Listing source commit: 85293e3e2b88

Evidence behind this overview
  • src/data-structures/trie/README.md

Pages that include this

Get the PrepKit newsletter

Optional. You don't need it to use PrepKit.

How we handle your email