Tries: Supporting a Variety of Data
Explore how tries support a variety of data beyond strings. Understand their structure for alphabets, sentences, binary numbers, and directory paths. Learn to apply tries for tasks such as autocomplete, pattern matching, range queries, and file system design through examples.
We'll cover the following...
We know that a trie is an
We'll learn about the different types of tries constructed on different datasets through examples.
Trie of alphabet
We can represent strings as a trie of letters of alphabet or characters, which can be used to implement features like search-autocomplete or creating dictionaries.
For example, a trie of words ["app", "apple", "appeal", "apply", "ape"] would look like the figure below.
Trie of words
Sentences can be represented as a trie of words. The tries are used for pattern matching in text and finding frequently used words and phrases.
For example, a trie of sentences ["Ben has two books", "Ben has two games", "Ben has three bats"] would look like the figure below.
Trie of bits
Binary numbers can be represented as a trie of bits. These tries can be used to perform range queries like finding the maximum XOR of binary digits in a list.
For example, a trie of binary numbers ["10110", "11001", "10101"] would look like the figure below.
Trie of directory paths
Directory paths can be represented as a trie of folder and file names. These tries can be used to design a file system that allows us to create new paths, associate them with different values, and visualize the directory structure of a system.
For example, a trie of directory paths ["home/user/William/file1", "home/user/William/file2", "home/user/Ben/file1"] would look like the figure below.