lec29 - Higher Order Tries • Key = Social Security...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Higher Order Tries • Key = Social Security Number. ƒ 441-12-1135 ƒ 9 decimal digits. • 10-way trie (order 10 trie). 0123456789 Height <= 10. Social Security Trie • 10-way trie ƒ Height <= 10. ƒ Search => <= 9 branches on digits plus 1 compare. • 100-way trie ƒ 441-12-1135 ƒ Height <= 6. ƒ Search => <= 5 branches on digits plus 1 compare. Social Security AVL & Red-Black • Red-black tree ƒ Height <= 2log2109 ~ 60. ƒ Search => <= 60 compares of 9 digit numbers. • AVL tree ƒ Height <= 1.44log2109 ~ 40. ƒ Search => <= 40 compares of 9 digit numbers. • Best binary tree. ƒ Height = log2109 ~ 30. Compressed Social Security Trie 0123456789 char# #ptr • char# = character/digit used for branching. ƒ Equivalent to bit# field of compressed binary trie. • #ptr = # of nonnull pointers in the node. Insert Insert 012345678. 012345678 Insert 015234567. 25 012345678 015234567 Null pointer fields not shown. Insert 25 012345678 Insert 015231671. 015234567 Insert 25 14 012345678 015231671 015234567 Insert 079864231. Insert 17 25 079864231 14 012345678 015231671 Insert 012345618. 015234567 Insert 17 25 079864231 14 1 7  012345678 012345618 015231671 015234567 Insert 011917352. Insert 17 1 2 5 079864231 011917352 14 1 7  012345678 012345618 015231671 015234567 Delete 17 1 2 5 079864231 011917352 14 1 7  012345678 012345618 015231671 015234567 Delete 011917352. Delete 17 2 5 079864231 14 1 7  012345678 012345618 015231671 Delete 012345678. 015234567 Delete 17 2 5 079864231 14  012345618 015231671 015234567 Delete 015231671. Delete 17 2 5 079864231 012345618 015234567 Variable Length Keys 25 Insert 0123. 14 012345678 015231671 015234567 Problem arises only when one key is a (proper) prefix of another. Variable Length Keys 25 Insert 0123. 14 012345678 015231671 015234567 Add a special end of key character (#) to each key to eliminate this problem. Variable Length Keys 25  Insert 0123. 4# 012345678 14 0123 015231671 015234567 End of key character (#) not shown. Tries With Edge Information • Add a new field (element) to each branch node. • New field points to any one of the element nodes in the subtree. • Use this pointer on way down to figure out skipped-over characters. Example  25 4# 012345678 14 0123 015231671 015234567 element field shown in blue. Etc. • Expected height of an order m trie is ~logmn. • Limit height to h (say 6). Level h branch nodes point to buckets that employ some other search structure for all keys in subtrie. Etc. • Switch from trie scheme to simple array when number of pairs in subtrie becomes <= s (say s = 6). ƒ Expected # of branch nodes for an order m trie when n is large and m and s are small is n/(s ln m). • Sample digits from right to left (instead of from left to right) or using a pseudorandom number generator so as to reduce trie height. Multibit Tries • Variant of binary trie in which the number of bits (stride) used for branching may vary from node to node. • Proposed for Internet router applications. ƒ Variable length prefixes. ƒ Longest prefix match. • Limit height by choosing node strides. ƒ Root stride = 32 => height = 1. ƒ Strides of 16, 8, and 8 for levels 1, 2, and 3 => only 3 levels. Multibit Trie Example 6 0 null 1 0 6 000 001 null 011 00 01 10 11 10 0 6 11 1 Multibit Tries • Node whose stride is s uses s bits for branching. ƒ Node has 2s children and 2s element/prefix fields. ƒ Prefixes that end at a node are stored in that node. ƒ Short prefixes are expanded to length represented by node. ƒ When root stride is 3, prefixes whose length is < 3 are expanded to length 3. ƒ P = 00* expands to P0 = 000* and P1 = 001*. ƒ If Q = 000* already exists P0 is eliminated because Q represents a longer match for any destination. Web Resource • See Web writeup for additional applications of tries. ƒ Prefix search. ƒ Automatic command (or phone number or URL) completion. ƒ LZW compression (longest matching prefix). Web Resource • See Web writeup for alternative node structures for tries. ƒ ƒ ƒ ƒ Array Chain Binary search tree Hash table ...
View Full Document

This note was uploaded on 03/22/2012 for the course CSE 3101 taught by Professor Shani during the Fall '10 term at University of Florida.

Ask a homework question - tutors are online