6 TRIES AND ADAPTING DATA STRUCTURES Flashcards
What is a binary search tree?
A data structure that organizes data based on less-than or greater-than comparisons.
What is the main problem addressed in the chapter?
Storing and searching strings in trees.
What is a trie?
A data structure that branches on a single character of the string at each level.
How do binary search trees store strings?
By sorting elements in alphabetical order.
What is the cost of comparing strings in a binary search tree?
It scales with the length of the strings.
What is the main advantage of using tries over binary search trees for strings?
Tries allow for more efficient searching by partitioning strings based on prefixes.
What does each node in a trie represent?
A prefix of the string.
How many branches can a trie node have for English words?
Up to 26 branches, one for each letter of the alphabet.
What is an internal node in a trie?
A node with at least one child.
What is a leaf node in a trie?
A node without any children.
What indicator is used to determine if a trie node represents a valid entry?
A Boolean is_entry.
True or False: Every node in a trie represents a valid entry.
False.
What is the purpose of the root node in a trie?
It indicates the start of the string.
How does searching in a trie differ from searching in a binary search tree?
In a trie, we choose branches based on the next letter in the string.
Fill in the blank: A trie allows for _______ splits at each node.
many-way
What does the trie data structure optimize for?
The additional structure in strings.
What is the analogy used to describe a trie?
An ultimate real-world filing system.
What does the term ‘partitioning function’ refer to in the context of tries?
It creates multi-way splits over the next character in the string.
What is a major drawback of binary search trees when used for string data?
The cost of string comparisons is higher than that of numbers.
What is the significance of the sequential nature of string comparisons?
We start at the first character and compare until a difference is found.
What happens when a trie contains strings with overlapping prefixes?
Some internal nodes may not represent valid entries.
How does a trie handle nodes with prefixes that are not valid entries?
It indicates this with a False value for is_entry.
What is the role of the Trie object in relation to the root node?
It wraps the root node and manages additional bookkeeping.
What is a characteristic of the branches in a trie?
They only create nodes for non-empty branches.