Binary Tries (Continued) : Split (K)
Binary Tries (Continued) : Split (K)
split(k). Similar to split algorithm for unbalanced binary search trees. Construct S and B on way down the trie. Follow with a backward cleanup pass over the constructed S and B.
Forward Pass
Suppose you are at node x, which is at level j of the input trie.
to level j of S and
to level j of B.
Forward Pass
x a b
to level j of B and b
to level j of S.
a
b
c
d
e
f g k = g.key = 101011
a
b
c
d
e
f g k = g.key = 101011
a
b
c
d
e
f g k = g.key = 101011
a
b c d
e
f g k = g.key = 101011
a
b c d
e
f g k = g.key = 101011
a
b c d f g e
k = g.key = 101011
a
b c d e k = g.key = 101011 f
a
f is an element node. c d e f b
a
Now backup on B. c d e f b
a
Now backup on B. c d e f b
a
Now backup on B. c Assume root of d is a branch node. e f d b
a
Complexity of split is O(height). c d e f b
Binary Trie
1 0 0 1 0011 0 4 1 0
2
1
3 0 0001
0
1 1101
0
1000
1
1001
0 1100
0
4
1
4
0
1000
1
1001
0 1100
1 1101
0
4
1
4
0
1000
1
1001
0 1100
1 1101
#branch nodes = n 1.
Insert
0 3 0 0001 1 0011 1 1 2
0
4
1
4
0
1000
1
1001
0 1100
1 1101
Insert 0010.
Insert
0 3 0 0001 0 1 4 1 1 1 2
0
4
1
4
0010
0011
0
1000
1
1001
0 1100
1 1101
Insert 0100.
Insert
0 2 1 1
2
1 0100 1 4 0 1 0 1 4 0 1100 1101 1
3
0 0001
4
0 1 0011
1000
1001
0010
Delete
0 2 1 1
2
1 0100 1 4 0 1 0 1 4 0 1100 1
3
0 0001
4
0 1 0011
1000
1001
1101
0010
Delete 0010.
Delete
0 2 3 0 0001 0 1 0011 1 1 2
1
0100 4
1
4
0
1000
1
1001
0 1100
1 1101
Delete 1001.
Delete
0 2 3 0 0001 0 1 0011 1 1 2
1
0100 1000
1
4 0 1100 1 1101
Split(k)
Similar to splitting an uncompressed binary trie.
Join(S,m,B)
Insert m into B to get B. |S| <= 1 or |B| = 1 handled as special cases as in the case of uncompressed tries. When |S| > 1 and |B| > 1, let Smax be the largest key in S and let Bmin be the smallest key in B. Let d be the first bit that is different in Smax and Bmin.
Cases To Consider
bit#(S) bit#(B)
0
a
1
b
0
c
1
d
bit#(S) = bit#(B)
bit#(S) < bit#(B)
d
0 1
bit#(S) = bit#(B)
s 0 a 1 b s 0 c 1 d
b
0 1
s
0 1
J(b,B)
b
0 1
b
0 1
J(S,c)
PATRICIA
Practical Algorithm To Retrieve Information Coded In Alphanumeric. Compressed binary trie. All nodes are of the same data type (binary tries use branch and element nodes).
Pointers to only one kind of node. Simpler storage management.
0
4 0 100 0 1 100 1
1
4 0 110 0
3
0011 0 1
1101 1 2
1001
4 0 0 1000 1 0 4 1 1100 1