Search⌘ K
AI Features

Implement Trie (Prefix Tree)

Understand how to implement a trie, also known as a prefix tree, to efficiently store and search strings. This lesson guides you through creating insert, search, and prefix search functions, enabling quick lookups of words and prefixes. By completing the exercises, you will gain practical skills in managing string data structures, useful for coding interviews and real-world applications.

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.

...