1 / 29

Digital Search Trees & Binary Tries

Digital Search Trees & Binary Tries. Analog of radix sort to searching. Keys are binary bit strings. Fixed length – 0110 , 0010 , 1010 , 1011 . Variable length – 01 , 00 , 101 , 1011 . Application – IP routing. IPv4 – 32 bit IP address. IPv6 – 128 bit IP address. IPv4 Addresses.

elvina
Download Presentation

Digital Search Trees & Binary Tries

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. Digital Search Trees & Binary Tries • Analog of radix sort to searching. • Keys are binary bit strings. • Fixed length – 0110, 0010, 1010, 1011. • Variable length – 01, 00, 101, 1011. • Application – IP routing. • IPv4 – 32 bit IP address. • IPv6 – 128 bit IP address.

  2. IPv4 Addresses • 32-bit address divided into four 8-bit segments. • a1.a2.a3.a4 • Each 8-bit segment is written as a decimal number in the range 0 – 255. • 123.1.44.161 • Class A Internet address. • a1 is net address. • Most significant bit of a1 is 0. • a2.a3.a4 gives host address within network. • <= 128 Class A nets. • Each Class A net may have up to 224~ 17 million hosts.

  3. IPv4 Addresses • Class B Internet address. • a1.a2 is net address. • Two most significant bits are 10. • a3.a4 gives host address within network. • Up to 214 = 16,384 Class B nets. • Each Class B net may have up to 216= 65,536 hosts. • IP addresses in a small company/department that has up to 256 hosts could have the format a1.a2.a3.*. • IP addresses of hosts in the same network/subnetwork have the same prefix.

  4. IPv4 Routers • Routing table entry … (prefix, nextMachine) • Prefix is a binary string whose length is <= 32 bits. • Packets whose destination address matches prefix may be routed to nextMachine. • (011*, M1) => all packets whose destination address begins with 011 may be routed next to machine M1. • (0111011*, M2) • Packet routing requires us to find the longest prefix (in the routing table) that matches the packet destination.

  5. IP Router Table • Collection of (prefix, nextMachine) pairs. • Operations. • Add a pair. • Remove a pair. • Find pair with longest matching prefix.

  6. Digital Search Tree • Assume fixed number of bits. • Not empty => • Root contains one dictionary pair (any pair). • All remaining pairs whose key begins with a 0 are in the left subtree. • All remaining pairs whose key begins with a 1 are in the right subtree. • Left and right subtrees are digital subtrees on remaining bits.

  7. 0110 0110 0010 Example • Start with an empty digital search tree and insert a pair whose key is 0110. • Now, insert a pair whose key is 0010.

  8. 0110 0010 1001 0110 0010 Example • Now, insert a pair whose key is 1001.

  9. 1001 0110 0010 1001 0110 0010 1011 Example • Now, insert a pair whose key is 1011.

  10. 1001 0110 0010 1011 1001 0110 0010 1011 0000 Example • Now, insert a pair whose key is 0000.

  11. 1001 0110 0010 1011 0000 Search/Insert/Delete • Complexity of each operation is O(#bits in a key). • #key comparisons = O(height). • Expensive when keys are very long.

  12. Binary Trie • 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.

  13. 0 1 0 0 1 0 1 0 0 1 1000 1100 0011 0001 1001 Example At most one key comparison for a search.

  14. Variable Key Length • Left and right child fields. • Left and right pair fields. • Left pair is pair whose key terminates at root of left subtree or the single pair that might otherwise be in the left subtree. • Right pair is pair whose key terminates at root of right subtree or the single pair that might otherwise be in the right subtree. • Field is null otherwise.

  15. 0 null 1 0 00 01100 10 11111 0 0 0000 001 1000 101 1 00100 001100 Example At most one key comparison for a search.

  16. 1 0 1 0 0 1 0 1 0 0 1 1000 1100 0011 0001 0111 1001 Fixed Length Insert Insert 0111. Zero compares.

  17. 1 0 1 0 0 1 0 1 0 0 1 1000 1100 0111 0011 0001 1001 Fixed Length Insert Insert 1101.

  18. 1 0 1 0 0 1 0 0 0 1 0 1001 0011 0001 1100 0111 1000 Fixed Length Insert 0 1 Insert 1101.

  19. 1 0 1 0 0 1 0 0 0 1 0 1 1000 0011 0001 0111 1100 1101 1001 Fixed Length Insert 0 1 Insert 1101. One compare.

  20. 1 0 1 0 0 1 0 1 0 0 0 1 0 1 1000 0011 0111 0001 1100 1101 1001 Fixed Length Delete Delete 0111.

  21. 0 1 0 0 1 0 1 0 0 0 1 0 1 1000 0011 0001 1100 1101 1001 Fixed Length Delete Delete 0111. One compare.

  22. 0 1 0 0 1 0 1 0 0 0 1 0 1 1000 0011 0001 1100 1101 1001 Fixed Length Delete Delete 1100.

  23. 0 1 1101 1001 0001 0011 1000 Fixed Length Delete 0 1 0 0 1 0 1 0 0 1 Delete 1100.

  24. 0 1101 1001 1000 0001 0011 Fixed Length Delete 0 1 0 0 1 0 1 0 0 1 Delete 1100.

  25. 1101 1001 1000 0011 0001 Fixed Length Delete 0 1 0 0 1 0 1 0 0 1 Delete 1100.

  26. 1001 1000 0011 0001 1101 Fixed Length Delete 0 1 0 0 1 0 1 0 0 1 Delete 1100. One compare.

  27. Fixed Length Join(S,m,B) • Insert m into B to get B’. • S empty => B’ is answer; done. • If you get to this step, the root of both S and B’ is a branch node. • S is element node => insert S element into B’; done; • B’ is element node => insert B’ element into S; done;

  28. S B’ J(S,B’) a b c c J(a,b) Fixed Length Join(S,m,B) • S has empty right subtree. + = J(X,Y)ajoin X and Y, all keys in X< all in Y.

  29. S B’ J(S,B’) a b c a J(b,c) Fixed Length Join(S,m,B) • S has nonempty right subtree. • Left subtree of B’ must be empty, because all keys in B’ > all keys in S. + = Complexity = O(height).

More Related