Search⌘ K
AI Features

Implement Trie (Prefix Tree)

Explore how to implement a trie (prefix tree) to store and search strings efficiently. This lesson teaches you to build three core functions: inserting words, searching complete words, and searching prefixes. By mastering tries, you'll improve your ability to solve problems involving prefix matching and optimize search operations relevant to coding interviews.

Statement

Trie is a tree-like data structure used to store strings. The tries are also called prefix trees because they provide very efficient prefix-matching operations. Implement a trie data structure with three functions that perform the following tasks:

  • Insert (word): This inserts a word into the trie.
  • Search (word): This searches the given word in the trie and returns TRUE, if found. Otherwise, return FALSE.
  • Search prefix (prefix): This searches the given prefix in the trie and returns TRUE, if found. Otherwise, return FALSE.

Constraints: ...