1 / 33

Binary Tries (continued)

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. x. a. b. a. Forward Pass.

azra
Download Presentation

Binary Tries (continued)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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. x a b a Forward Pass • Suppose you are at node x, which is at level j of the input trie. • If bit j of k is 1, move to root of b and add to level j of S and to level j of B.

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

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

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

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

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

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

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

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

  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. S B a b c d e f Backward Cleanup Pass Example fis an element node.

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

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

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

  16. S B a b c d e 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. 0 1 0 0 1 0 1 0 0 0 1 0 1 1001 0011 0001 1100 1101 1000 Binary Trie 1 2 3 4 4 bit# field shown in black outside branch node.

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

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

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

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

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

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

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

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

  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 Smaxbe 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 Smax andB’min.

  29. bit#(S) bit#(B’) 0 1 0 1 a b c d B’ S Cases To Consider • d < min{bit#(S), bit#(B’)} • bit#(S) = bit#(B’) • bit#(S) < bit#(B’) • bit#(S) > bit#(B’)

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

  31. s s 0 1 0 1 a b c d B’ S bit#(S) = bit#(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. s s b’ 0 1 0 1 0 1 a J(b,B’) a b c d B’ S bit#(S) < bit#(B’) = +

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

More Related