Download presentation

Presentation is loading. Please wait.

Published bySabastian Raybuck Modified about 1 year ago

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 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 Sandto level j of B.

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

4
Forward Pass Example b a c d e fg S = nullB = null k = g.key = 101011

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

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

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

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

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

10
Forward Pass Example d b B e c a S f

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 e c a S f d b B f is an element node.

13
Backward Cleanup Pass Example e c a S f d b B Now backup on B.

14
Backward Cleanup Pass Example e c a S f d b B Now backup on B.

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

16
Backward Cleanup Pass Example e c a S f d b B Complexity of split is O(height).

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 0 1 0001 0011 1000 1001 0 0 0 0 0 1 1 1 1100 1101 0 0 1 1 2 3 4 4 bit# field shown in black outside branch node.

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

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

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

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

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

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

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

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

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

28
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 S max be the largest key in S and let B’ min be the smallest key in B’. Let d be the first bit which is different in S max and B’ min.

29
Cases To Consider d < min{bit#(S), bit#(B’)} bit#(S) = bit#(B’) bit#(S) < bit#(B’) bit#(S) > bit#(B’) 01 bit#(S) ab S 01 cd B’ bit#(B’)

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

31
bit#(S) = bit#(B’) 01 s ab S 01 s cd 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’.

32
bit#(S) < bit#(B’) 01 s ab S 01 b’ cd B’ 01 s a J(b,B’)

33
bit#(S) > bit#(B’) 01 s ab S 01 b’ cd B’ 01 b’ J(S,c)d Complexity is O(max{height(S), height(B)}). S max and B’ min are found just once.

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google