CS 225 Data Structures and Software Principles - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

CS 225 Data Structures and Software Principles

Description:

raft. star. start. stir. Words in Trie. One (Patricia) Tree Application ... raft. star. start. stir. Words in Trie. de la Briandais Tree Example. Hybrid Structures ... – PowerPoint PPT presentation

Number of Views:168
Avg rating:3.0/5.0
Slides: 14
Provided by: anandkris
Category:

less

Transcript and Presenter's Notes

Title: CS 225 Data Structures and Software Principles


1
CS 225 Data Structures and Software Principles
  • Section 12
  • Tries

2
Agenda
  • Tries
  • Basics
  • Jasons Code
  • Patricia Trees
  • De La Briandais Trees
  • Hybrid Trees

3
Tries
  • Data structure optimized for lookups on a key
    that can be decomposed into characters
  • Take into account overlapping strings
  • Regular expression search
  • Pattern searches in images
  • Non-compact tries
  • De La Briandais Trees, Patricia Trees

4
Trie Representation
  • Tries are represented using a tree of arrays
  • For a character set of size k, the corresponding
    Trie structure is a (k1)-ary tree

5
Tries
  • The i-th character (starting at 0) in the data
    corresponds to the node at depth i
  • Need a mapping of character to an index in the
    array
  • The extra one cell in the array is used to hold a
    null character represented by ?
  • Points to a leaf
  • Ideally, no need to store key in a leaf, since it
    is completely determined by path followed
  • Info stored at the leaf
  • Spend only constant time at each level

6
Trie Example
Words in Trie
raft star start stir
7
Tries
  • Running time of Find operation O(L) where L is
    the length of the string we are looking for
  • Unique trie for any set of search keys
  • Advantage NOT dependent on the number of strings
    we have in the Trie structure
  • Disadvantage memory waste
  • 27 cell array, one per character needed for
    Strings
  • Space (k1) nodes sizeof(pointer)

8
Jasons CodeTrieNode Data
  • TrieNode
  • int nodeLevel // level of the node
  • bool isLeaf
  • ArrayltTrieNodegt subtries // array of ptrs to
    nodes
  • String key // string key in leaf nodes
    Etype storedInfo

9
Patricia Trees
  • Acronym Practical Algorithm To Retrieve
    Information Coded In Alphanumeric
  • Trick only allocate arrays that make a
    decision
  • Do not store nodes with only one non-NULL cell
  • Store in each node the index of the character
    position on which it discriminates
  • Tradeoff Less space required, but more work for
    Insert and Remove
  • Key no longer uniquely determined by path
  • Now we must store keys in the leaf

10
Patricia Tree Example
Words in Trie
raft star start stir
a b c
r
s
z
0

a
i
raft
2
skipt
t
stir
4
skipr
star
start
11
One (Patricia) Tree Application
  • Communication Networks (CS 438)
  • Task of efficiently finding the longest match
    between an IP address and variable-length
    prefixes in a forwarding table (due to CIDR)
  • Given packet for 128.174.5.130, where would it go?

Net/MaskLength NextHop
128.174.0.0/16 A
128.0.0.0/1 B
64.0.0.0/2 C
0.0.0.0/2 D
1000 0000 1011 1100
12
De La Briandais Trees
  • Trick convert arrays in Trie to sparse arrays
  • Allocate space only for used cells in the arrays
  • At each level we now have a linked list
  • Array cells are now nodes that not only point
    down, but to the next used character on that
    level
  • Advantage can save much space good when the
    linked lists are not long
  • Disadvantage search is now dependent on k
    (alphabet size)

13
de la Briandais Tree Example
Words in Trie
raft star start stir
14
Hybrid Structures
  • Patricia/de la Briandais
  • Uses both optimizations
  • We eliminate all one node linked lists in the de
    la Briandais tree
  • Trie/Patricia/de la Briandais
  • Highly optimized data structure
  • Some levels have arrays and others have linked
    lists
Write a Comment
User Comments (0)
About PowerShow.com