Professional Documents
Culture Documents
AN EXCELLENT DATA
STRUCTURE FOR
STRINGS
Tries
Instructor
Md. Shamsujjoha
Senior Lecturer
Department of CSE
East West University
Presented by:
Md. Naim Khan
Id :2014-2-60-092
Md. Riad Khan
Id :2014-1-60-040
Slide
2
Overview
Slide
3
History
Slide
4
Definition of Tries
Slide
5
Properties of a tries
A multi-way tree.
Each node has from 1 to n children.
Each edge of the tree is labeled with a character.
Each leaf nodes corresponds to the stored string,
which is a concatenation of characters on a path
from the root to this node.
Slide
6
Standard Trie
The standard trie for a set of strings S is an ordered
tree such that:
Slide
7
Standard Tries - Insertion
Strings ={an, and, any, at}
Root
n t
d y
Slide
8
Example of Standard tries
Root
b s
e i u e t
o
a l l l
d y
c p
r l l l
k
Slide
9
Handling keys(strings)
When a key(string) is a prefix of another key.
How can we know that “an” is a word?
Example: an, and
Root
n t
d y
Slide
10
Handling keys(strings)
We add a special termination symbol “$’’
We append the “$’’ to each keyword
Strings={ an, and, any, at}
Root
n t
$ d y $
$ $
Slide
11
Standard Tries- Searching
Search hit: Node where search ends has a $ symbol
Search - sea
Root
a s
n t e
$ d y $ a t
$ $ $ $
Slide
12
Standard Tries- Deletion
Three cases
Slide
13
Standard Tries- Deletion
Word not found
return false.
Word exists as a stand alone word
part of any other word
does not a part of any other word
Slide
14
Standard Tries- Deletion
Part of any other word
Delete - sea
Root
a s
Deleted
n t e
$ d y $ a t
$ $ $ $
Slide
15
Standard Tries-Deletion
Does not a part of any other word
Delete - set
Root
Deleted
a s
n t e
$ d y $ t
$ $ $
Slide
16
Standard Tries- Deletion
Word exists as a prefix of any other word.
Delete - an
Root
Deleted
a s
n t e
$ d y $ a t
$ $ $ $
Slide
17
Compressd Tries
Slide
18
Compressed Trie- Example
In order to understand Compressed Trie we need to
see the Standard Trie Example:
Standard Trie
Root
b s
e i u e t
o
a l l l
d y
c p
r l l l
k
Slide
19
Compressed Tries Example
Compressed Tries:
S = { bear, bell, bid, bull, buy, sell, stock, stop }
s
b
e id u ell to
ck p
ar ll ll y
Slide
20
Suffix Tries
Slide
21
Example of Suffix Tries
Let us consider an example text “soon$″.
soon$ Root
s $
oon$
o n
on$ o
n$ o n $
o
$
n $
n Done
$
$
Slide
22
Example of Suffix Tries
After alphabetically ordered the trie will look like
Root
$
n o s
$ o
o n
o
n $
n
$
$
Understanding Requirements
Slide
23
References
Web pages
http://www.mathcs.emory.edu/~cheung/Courses/323/Syll
abus/Text/trie01.html
http://fbim.fh-
regensburg.de/~saj39122/sal/skript/progr/pr45102/Tries.p
df
http://www.ideserve.co.in/learn/trie-delete
http://algs4.cs.princeton.edu/lectures/52Tries.pdf
Book
Data Structure and Algorithm
by Alfred V. Aho
Jeffery D. Ullman
John E.HopcroftJohn
Slide
24
Questions or Suggestions
Slide
25
Thank you
Inquiry
riadmrk.khan@gmail.com
naim1248@gmail.com
Slide
26