Trees
Learn about tries and binary indexed trees for efficient search implementations!
StartImplementing Tries in Python
Lesson 1 of 2
- 1In the article, we introduced the prefix tree data structure (better known as a trie), its properties, and some of its applications. In this lesson, we will see how we can implement a trie. Recall…
- 2Let’s define the TrieNode class we will use to implement a trie. To represent subsequent characters in a string, a TrieNode object contains a dictionary that maps a character to an instance of Tri…
- 3In this exercise, we will describe the algorithm that adds a word to a trie. We will then implement this algorithm in the add_string() function of the Trie class. We will be implementing this algor…
- 4In this exercise, we will search for a string in a trie. A string is loaded into a trie for one of two reasons: * The trie represents a dictionary of words. * The string contains some relevant info…
- 5In this exercise, we will work on the count_prefix() method in our Trie class. As its name suggests, this function will count the number of words with a prefix up to some character. We track this c…
- 6Now that you have finished constructing your trie data structure, in this exercise, you will get a chance to see it in action. In the following checkpoints, you will add strings, search for string…
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory