Trees

Concept shape

Core
Definition

A trie stores words by sharing prefixes through character nodes.

Step 1 / 5
Concept shape
Current lesson

Tries Lab

Trees Core

Tries

Welcome to the Tries concept lab. A trie stores words by sharing prefixes through character nodes. The must know points are: Good for prefix queries. Each path represents a string prefix. Memory can be high for large alphabets. The common operations are: insert O(L), search O(L), startsWith O(L). The complexity shape is O(word length). Watch out for these pitfalls: Forgetting an end-of-word marker. Creating many sparse child maps. Related algorithms include Trie Insert and Search, Word Search.

Concept details

A trie stores words by sharing prefixes through character nodes.

Must know

  • Good for prefix queries.
  • Each path represents a string prefix.
  • Memory can be high for large alphabets.

Complexity

O(word length)

Open deeper visual structure lesson
1.0x