Presentation is loading. Please wait.

Presentation is loading. Please wait.

Binary Tries (continued)

Similar presentations


Presentation on theme: "Binary Tries (continued)"— Presentation transcript:

1 Binary Tries (continued)
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.

2 Forward Pass a x b a to level j of S and to level j of B.
Suppose you are at node x, which is at level j of the input trie. a x b If bit j of k is 1, move to root of b and add a to level j of S and to level j of B.

3 Forward Pass a x b b to level j of B and to level j of S.
If bit j of k is 0, move to root of a and add b to level j of B and to level j of S.

4 Forward Pass Example S = null B = null b a c d e f g
g is an element node. k = g.key =

5 Forward Pass Example a S B b c d e f g k = g.key =

6 Forward Pass Example a S B b c d e f g k = g.key =

7 Forward Pass Example a S b B c d e f g k = g.key =

8 Forward Pass Example c a S b B d e f g k = g.key =

9 Forward Pass Example c a S b B e d f g k = g.key =

10 Forward Pass Example e c a S d b B f k = g.key =

11 Backward Cleanup Pass Retrace path from current nodes in S and B toward roots of respective tries. Eliminate branch nodes that are roots of subtries that have fewer than 2 dictionary pairs.

12 Backward Cleanup Pass Example
f d b B Suppose f is an element node.

13 Backward Cleanup Pass Example
Now backup on B. f

14 Backward Cleanup Pass Example
Now backup on B. f

15 Backward Cleanup Pass Example
Now backup on B. Assume root of d is a branch node. f

16 Backward Cleanup Pass Example
Complexity of split is O(height). f

17 Compressed Binary Tries
No branch node whose degree is 1. Add a bit# field to each branch node. bit# tells you which bit of the key to use to decide whether to move to the left or right subtrie.

18 Binary Trie bit# field shown in black outside branch node. 1 1 0001
1 0001 0011 1000 1001 1100 1101 2 3 4 4 bit# field shown in black outside branch node.

19 Compressed Binary Trie
1 1 3 2 1 1 0001 0011 4 4 1 1 1000 1001 1100 1101 bit# field shown in black outside branch node.

20 Compressed Binary Trie
1 0001 0011 1000 1001 1100 1101 2 3 4 #branch nodes = n – 1.

21 Insert 1 0001 0011 1000 1001 1100 1101 2 3 4 Insert 0010.

22 Insert 1 0001 1000 1001 1100 1101 2 3 4 0010 0011 Insert 0100.

23 Insert 1 1 2 2 1 1 3 0100 4 4 1 1 1 0001 4 1000 1001 1100 1101 1 0010 0011

24 Delete 0001 1 1000 1001 1100 1101 2 3 4 0010 0011 0100 Delete 0010.

25 Delete 0001 1 1000 1001 1100 1101 2 3 4 0011 0100 Delete 1001.

26 Delete 0001 1 1000 1100 1101 2 3 4 0011 0100

27 Split(k) Similar to splitting an uncompressed binary trie.

28 Join(S,m,B) 3-way to 2-way join
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 B’min be the smallest key in B’. Let d be the first bit that is different in Smax and B’min.

29 Cases To Consider B’ S d < min{bit#(S), bit#(B’)}
1 bit#(S) a b S c d B’ bit#(B’) d < min{bit#(S), bit#(B’)} d >= min{bit#(S), bit#(B’)} bit#(S) = bit#(B’) bit#(S) < bit#(B’) bit#(S) > bit#(B’) d >= min gives rise to 3 sub cases.

30 d < min{bit#(S), bit#(B’)}
Bit d of Smax must be 0. 1 d S B’

31 bit#(S) = bit#(B’) 1 s a b S c d B’ Not possible, because keys in b are larger than those in c. However, all keys in S are supposed to be smaller than those in B’. Note, all branch nodes have 2 children in a compressed binary trie. Since d >= s, d=s and all keys in S and b agree on first d-1 bits.

32 bit#(S) < bit#(B’) = + B’ S 1 s a J(b,B’) 1 s a b 1 b’ c d
1 s a J(b,B’) 1 s a b S 1 b’ c d B’ = + All keys in B’ have bit s=1; otherwise all keys in B’ < those in b.

33 bit#(S) > bit#(B’) = + B’ S Smax and B’min are found just once. 1
1 b’ J(S,c) d 1 s a b S 1 b’ c d B’ = + Complexity is O(max{height(S), height(B)}). Smax and B’min are found just once.

34 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.

35 Compressed Binary Trie To Patricia
1 0001 0011 1000 1001 1100 1101 2 3 4 Move each element into an ancestor or header node.

36 Compressed Binary Trie To Patricia
1 2 3 4 0001 1101 0011 1100 1001 1000


Download ppt "Binary Tries (continued)"

Similar presentations


Ads by Google