Higher Order Tries - PowerPoint PPT Presentation

About This Presentation
Title:

Higher Order Tries

Description:

Automatic command (or phone number or URL) completion. LZW compression. Web Resource See Web writeup for alternative node structures for tries. – PowerPoint PPT presentation

Number of Views:86
Avg rating:3.0/5.0
Slides: 28
Provided by: Preferr823
Category:

less

Transcript and Presenter's Notes

Title: Higher Order Tries


1
Higher Order Tries
  • Key Social Security Number.
  • 441-12-1135
  • 9 decimal digits.
  • 10-way trie (order 10 trie).

Height lt 10.
2
Social Security Trie
  • 10-way trie
  • Height lt 10.
  • Search gt lt 9 branches on digits plus 1 compare.
  • 100-way trie
  • 441-12-1135
  • Height lt 6.
  • Search gt lt 5 branches on digits plus 1 compare.

3
Social Security Trie
  • 109-way trie
  • Height lt 2.
  • Search gt lt 1 branch on a digit plus 1 compare.

4
Memory Accesses
  • During a search, we can compute needed field of a
    branch node.
  • Access only that field.

T
0
1
2
3
4
5
6
7
8
9
key 46
5
Memory Accesses
  • memory accesses 1 per encountered branch node
    those needed for an element node.

T
0
1
2
3
4
5
6
7
8
9
key 46
6
Binary Search Trees
  • Red-black tree
  • Height lt 2log2109 60.
  • Search gt up to 60 compares of 9 digit numbers
    and up to 60 memory accesses.
  • AVL tree
  • Height lt 1.44log2109 40.
  • Search gt up to 40 compares of 9 digit numbers
    and up to 40 memory accesses.
  • Best binary tree.
  • Height log2109 30.

7
Higher Order Search Trees
10 30 50
  • height can be lt log2 n
  • nodes accessed is reduced
  • but cache misses/node increases as node size
    increases
  • worst-case compares remains gt log2 n

8
Compressed Social Security Trie
Branch Node Structure
  • char character/digit used for branching.
  • Equivalent to bit field of compressed binary
    trie.
  • ptr of nonnull pointers in the node.

9
Insert
  • Insert 012345678.

012345678
Insert 015234567.
Null pointer fields not shown.
10
Insert
Insert 015231671.
11
Insert
Insert 079864231.
12
Insert
Insert 012345618.
13
Insert
1
7
Insert 011917352.
14
Insert
1
7
2
2
5
1
3
079864231
011917352
1
4
1
7
8
6
012345678
012345618
015234567
015231671
15
Delete
Delete 011917352.
16
Delete
1
7
2
2
5
3
079864231
1
4
1
7
8
6
012345678
012345618
015234567
015231671
Delete 012345678.
17
Delete
1
7
2
2
5
3
079864231
1
4
6
012345618
015234567
015231671
Delete 015231671.
18
Delete
1
7
2
2
5
3
079864231
012345618
015234567
19
Variable Length Keys
Insert 0123.
Problem arises only when one key is a (proper)
prefix of another.
20
Variable Length Keys
End of key character () not shown.
21
Variable Length Keys
End of key character () not shown.
22
Variable Length Keys
One trie per length.
Hashtable of tries.
23
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.

24
Example
element field shown in blue.
25
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.

26
Etc.
  • Switch from trie scheme to simple array when
    number of pairs in subtrie becomes lt 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.

27
Web Resource
  • See Web writeup for additional applications of
    tries.
  • Prefix search.
  • Automatic command (or phone number or URL)
    completion.
  • LZW compression.

28
Web Resource
  • See Web writeup for alternative node structures
    for tries.
  • Array
  • Chain
  • Binary search tree
  • Hash table
Write a Comment
User Comments (0)
About PowerShow.com