6 TRIES AND ADAPTING DATA STRUCTURES Flashcards

1
Q

What is a binary search tree?

A

A data structure that organizes data based on less-than or greater-than comparisons.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the main problem addressed in the chapter?

A

Storing and searching strings in trees.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a trie?

A

A data structure that branches on a single character of the string at each level.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do binary search trees store strings?

A

By sorting elements in alphabetical order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the cost of comparing strings in a binary search tree?

A

It scales with the length of the strings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the main advantage of using tries over binary search trees for strings?

A

Tries allow for more efficient searching by partitioning strings based on prefixes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does each node in a trie represent?

A

A prefix of the string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How many branches can a trie node have for English words?

A

Up to 26 branches, one for each letter of the alphabet.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an internal node in a trie?

A

A node with at least one child.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a leaf node in a trie?

A

A node without any children.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What indicator is used to determine if a trie node represents a valid entry?

A

A Boolean is_entry.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

True or False: Every node in a trie represents a valid entry.

A

False.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the purpose of the root node in a trie?

A

It indicates the start of the string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does searching in a trie differ from searching in a binary search tree?

A

In a trie, we choose branches based on the next letter in the string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Fill in the blank: A trie allows for _______ splits at each node.

A

many-way

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the trie data structure optimize for?

A

The additional structure in strings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the analogy used to describe a trie?

A

An ultimate real-world filing system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What does the term ‘partitioning function’ refer to in the context of tries?

A

It creates multi-way splits over the next character in the string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a major drawback of binary search trees when used for string data?

A

The cost of string comparisons is higher than that of numbers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the significance of the sequential nature of string comparisons?

A

We start at the first character and compare until a difference is found.

21
Q

What happens when a trie contains strings with overlapping prefixes?

A

Some internal nodes may not represent valid entries.

22
Q

How does a trie handle nodes with prefixes that are not valid entries?

A

It indicates this with a False value for is_entry.

23
Q

What is the role of the Trie object in relation to the root node?

A

It wraps the root node and manages additional bookkeeping.

24
Q

What is a characteristic of the branches in a trie?

A

They only create nodes for non-empty branches.

25
What is the first step in the trie search process?
Check the first character for a match
26
How does the trie search process differ at the second level?
Check the second character for a match
27
What does the Trie wrapper function do?
Hides the reference to the root node and the initial counter
28
What is the purpose of the index parameter in the recursive search function?
Tracks the position of the character being checked
29
What does the TrieNodeSearch function check when the index equals the length of the target?
If current.is_entry is True
30
What happens if the current node is not a valid entry at the end of the search?
Returns null
31
What does the character mapping function do in the trie search?
Maps the character to the correct index in the array
32
How can we determine if a string is not in the trie?
By hitting a dead end in the search
33
True or False: The number of comparisons for a successful trie search depends on the number of strings stored in the trie.
False
34
What is one key advantage of using a trie over a binary search tree?
Search cost is independent of the number of strings stored
35
What happens during the insertion of a string into a trie?
Progress down the tree and create a subtree at a dead end
36
What does the TrieInsert function do?
Calls the recursive search function with the root node
37
What does the is_entry flag indicate in a trie node?
Whether the current node represents a valid entry
38
What is the process for deleting a node from a trie?
Progress up the tree deleting nodes that are no longer needed
39
What does the TrieDelete function start with?
The root node and the correct index
40
What condition prevents a node from being deleted during the deletion process?
If it has at least one non-empty child or is an entry
41
What does the TrieNodeDelete function return?
A Boolean indicating whether the current node can be safely deleted
42
What is a key disadvantage of tries compared to binary search trees?
Higher memory usage due to storing multiple nodes for overlapping prefixes
43
True or False: Deletion in a trie is proportional to the length of the target string.
True
44
What is an example use case for a trie in a word processor?
Tracking words in a dictionary for spell-checking
45
How do tries optimize the cost of operations?
By using the structure inherent in the data
46
What type of data structures can benefit from using a trie, apart from words?
Structured labels like serial numbers or SKU codes
47
Fill in the blank: The trie structure is particularly effective when the number of strings with _______ increases.
similar prefixes
48
What is the main theme illustrated by the use of tries in data structures?
Using the structure inherent in data to improve algorithmic efficiency