Digital Search Tree
Digital Search Tree
2
Example
• Start with an empty digital search tree
and insert a pair whose key is 0110.
0110
0110
0010
3
Example
0110 0110
4
Example
0110 0110
1011
5
Example
0110 0110
6
Search/Insert/Delete
0110
0010 1001
0000 1011
• Information Retrieval.
• At most one key comparison per
operation.
• Fixed length keys.
– Branch nodes.
• Left and right child pointers.
• No data field(s).
– Element nodes.
• No child pointers.
• Data field to hold dictionary pair.
8
Example
0 1
0 0 1
1100
0 1 0
0001 0011
0 1
1000 1001
At most one key comparison for a search.
9
Fixed Length Insert
0 1
0 0 1
1
1100
0 1 0111 0
0001 0011
0 1
1000 1001
0 1
0 0 1
1
1100
0 1 0111 0
0001 0011
0 1
1000 1001
Insert 1101.
11
Fixed Length Insert
1100
0 1
0 0 1
1
0 1 0111 0 0
0001 0011
0 1 0
1000 1001
Insert 1101.
12
Fixed Length Insert
0 1
0 0 1
1
0 1 0111 0 0
0001 0011
0 1 0 1
1000 1001 1100 1101
Insert 1101. One compare. 13
Fixed Length Delete
0 1
0 0 1
1
0 1 0111 0 0
0001 0011
0 1 0 1
1000 1001 1100 1101
Delete 0111.
14
Fixed Length Delete
0 1
0 0 1
0 1 0 0
0001 0011
0 1 0 1
1000 1001 1100 1101
Delete 0111. One compare. 15
Fixed Length Delete
0 1
0 0 1
0 1 0 0
0001 0011
0 1 0 1
1000 1001 1100 1101
Delete 1100.
16
Fixed Length Delete
0 1
0 0 1
0 1 0 0
0001 0011
0 1 1
1000 1001 1101
Delete 1100. 17
Fixed Length Delete
1101
0 1
0 0 1
0 1 0 0
0001 0011
0 1
1000 1001
Delete 1100. 18
Fixed Length Delete
1101
0 1
0 0 1
0 1 0
0001 0011
0 1
1000 1001
Delete 1100.
19
Fixed Length Delete
0 1
0 0 1
1101
0 1 0
0001 0011
0 1
1000 1001
21
Binary Trie
1
0 1
2
0 0 1
3
0 1 0 0
0001 4 4
0011
0 1 0 1
1000 1001 1100 1101
#branch nodes = n – 1. 24
Insert
0 1
1
3 2
0 1
0 1
0001 0011
4 4
0 1 0 1
1000 1001 1100 1101
Insert 0010. 25
Insert
0 1
1
3 2
0 1
0 1
0001 4
0 1 4 4
0010 0011 0 1 0 1
1000 1001 1100 1101
Insert 0100. 26
Insert
1
0
1
2 2
0 1 0 1
3
0100 4 4
0 1
0 1 0 1
0001 4 1000 1001 1100
0 1 1101
0010 0011
27
Delete
1
0
1
2 2
0 1 0 1
3
0100 4 4
0 1
0 1 0 1
0001 4 1000 1001 1100 1101
0 1
0010 0011
Delete 0010.
28
Delete
0 1
1
2 2
0 1 0 1
3
0100 4 4
0 1
0 1 0 1
0001 0011 1000 1001 1100 1101
Delete 1001. 29
Delete
0 1
1
2 2
0 1 0 1
3
0100
1000 4
0 1
0 1
0001 0011
1100 1101
30
Patricia
bit# LC Pair RC
33
Compressed Binary Trie To Patricia
0 1
1
3 2
0 1
0 1
0001 0011
4 4
0 1 0 1
1000 1001 1100 1101
0 1101
3 1
0011 2
0 1001
1 0 1
4 4
1000 1100
1
0 1
0 35
Insert
Insert 0000101 0
0000101
Insert 0000000 0
0000101
5
0000000
36
Insert 0000000
Insert 0
0000101
5
0000000
0
0000101
Insert 0000010
5
0000000
6
0000010
37
0 Insert
0000101 0
0000101
5
0000000 4
0001000
6
0000010 5
0000000
6
0000010
Insert 0001000 38
Insert
0
0000101
4
0001000
5
0000000
6
0000010
Insert 0000100 39
Insert
0
0000101
4
0001000
5
0000000
6 7
0000010 0000100
Insert 0001010 40
Insert
0
0000101
4
0001000
5 6
0000000 0001010
6 7
0000010 0000100
Insert 0001010 41
Delete
• Let p be the node that contains the
dictionary pair that is to be deleted.
• Case 1: p has one self pointer.
• Case 2: p has no self pointer.
42
p Has One Self Pointer
p p
0001000 0000000
43
p Has No Self Pointer
• Let q be the node that has a back pointer to p.
• Node q was determined during the search for
the pair with the delete key k.
p
0001000
Blue pointer could
be red or black.
q
y
44
p Has No Self Pointer
p
0001000
q
y
r
z
q
y
r
z
q
y
r
z
q
y
r
z Node q now has been
removed from trie.
• Change forward pointer to q from
parent(q) to child of q. 48
Tries
Definition
• A trie is an index structure that is
particulary useful when key values are of
varying size.
51
• Since we assume that each character is one of the
26 letters of the alphabet, a branch node has 27
pointer data member; the extra pointer is used
for the blank character which is used to
terminate all keys.
52
Sampling Strategies
53
Trie constructed for data of the preceding one
sampling one character at a time, from right to left.
54
An optimal trie for the first one trie sampling on the
first level done by using the fourth character of the
key values.
55
• The key value may be interpreted as consisting of
digits using any radix we desire.
– Using a radix of 27^2 would result in two-character sampling.
56
Number of levels is limited to 3; keys have been
sampled from left to right, one character at a time.
57
Insertion into a Trie
58
The result of insertion.
59
Deletion from a Trie
60
• To facilitate deletion from tries, it is useful to
add a count data member in each branch node.
(This data member contains the number of
children the node has.)
61