Data structure tries
-
Upload
naim-khan -
Category
Engineering
-
view
252 -
download
0
Transcript of Data structure tries
![Page 1: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/1.jpg)
TRIES
AN EXCELLENT DATA STRUCTURE FOR
STRINGS
![Page 2: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/2.jpg)
Tries Instructor Md. Shamsujjoha Senior Lecturer Department of CSE East West University
Presented by:Md. Naim KhanId :2014-2-60-092Md. Riad KhanId :2014-1-60-040
Slide 2
![Page 3: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/3.jpg)
Overview
History & Definition Types of Tries Standard Tries Compressed Tries Suffix Tries Conclusion
Slide 3
![Page 4: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/4.jpg)
History
The term trie comes from retrieval. This term was coined by Edward Fredkin, who
pronounce it tri as in the word retrieval.
Slide 4
![Page 5: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/5.jpg)
Definition of Tries
A data structure for representing a collection of strings.
In computer science, a trie, also called digital tree and sometimes radix tree or prefix tree.
Tries support fast pattern matching.
Slide 5
![Page 6: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/6.jpg)
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
![Page 7: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/7.jpg)
Standard Trie The standard trie for a set of strings S is an
ordered tree such that:
*Each node but the root is labeled with a character.
*The children of a node are alphabetically ordered.
*The paths from the external nodes to the root yield the strings of S.
Slide 7
![Page 8: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/8.jpg)
Standard Tries - Insertion Strings ={an, and, any, at}
n
a
d
t
y
Root
Slide 8
![Page 9: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/9.jpg)
Example of Standard tries Example: Standard trie for the set of strings
S = { bear, bell, bid, bull, buy, sell, stock, stop }
te
s
uie
b
ollla d yc
k
plllr
Root
Slide 9
![Page 10: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/10.jpg)
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
n
a
d
t
y
Root
Slide 10
![Page 11: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/11.jpg)
Handling keys(strings) We add a special termination symbol “$’’ We append the “$’’ to each keyword Strings={ an, and, any, at}
n
a
d
t
y
Root
$
$ $
$
Slide 11
![Page 12: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/12.jpg)
Standard Tries- Searching Search hit: Node where search ends has a $
symbol Search - sea
n
a
d
t
y
Root
a t
e
s
$
$$
$
$ $Slide 12
![Page 13: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/13.jpg)
Standard Tries- Deletion
Three cases
Word not found…! Word exists as a stand alone word.
Word exists as a prefix of another word
Slide 13
![Page 14: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/14.jpg)
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
![Page 15: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/15.jpg)
Standard Tries- Deletion Part of any other word Delete - sea
n
a
d
t
y
Root
a t
e
s
$
$$
$
$ $
Slide 15
Deleted
![Page 16: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/16.jpg)
Standard Tries-Deletion Does not a part of any other word Delete - set
n
a
d
t
y
Root
t
e
s
$
$
$
$ $
Slide 16
Deleted
![Page 17: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/17.jpg)
Standard Tries- Deletion Word exists as a prefix of any other word. Delete - an
n
a
d
t
y
Root
a t
e
s
$
$$
$
$ $
Slide 17
Deleted
![Page 18: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/18.jpg)
Compressd Tries
Tries with nodes of degree at least 2 Obtained by standard tries by
compressing chains of redundant nodes
Slide 18
![Page 19: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/19.jpg)
Compressed Trie- Example In order to understand Compressed Trie we
need to see the Standard Trie Example:
te
s
uie
b
ollla d yc
k
plllr
Root Standard Trie
Slide 19
![Page 20: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/20.jpg)
Compressed Tries Example Compressed Tries: S = { bear, bell, bid, bull, buy, sell, stock,
stop }
b s
e u toid ell
llar ll y ck p
Root Compressed Trie
Slide 20
![Page 21: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/21.jpg)
Suffix Tries
A suffix trie is a compressed trie for all the suffixes of a text.
Suffix trie are a space-efficient data structure to store a string that allows many kinds of queries to be answered quickly.
Slide 21
![Page 22: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/22.jpg)
Example of Suffix Tries Let us consider an example text “soon$″.
Root
s
o
o
n
o
o
n
n
n
$ $
$
$
$
Slide 22
soon$
oon$
$
n$
on$
Done
![Page 23: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/23.jpg)
After alphabetically ordered the trie will look like
Root
s
o
o
n
o
o
n
n
n
$$
$
$
$
Example of Suffix Tries
![Page 24: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/24.jpg)
Understanding Requirements
Insertion is faster as compared to the Hash Table
Lookup is much more faster than Hash Table implementations
There are no collision of different keys in tries
Slide 23
![Page 25: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/25.jpg)
References Web pages http://www.mathcs.emory.edu/~cheung/Cours
es/323/Syllabus/Text/trie01.html http://fbim.fh-regensburg.de/~saj39122/sal/sk
ript/progr/pr45102/Tries.pdf http://www.ideserve.co.in/learn/trie-delete http://algs4.cs.princeton.edu/lectures/52Tries.
pdfBook Data Structure and Algorithm by Alfred V. Aho Jeffery D. Ullman John E.HopcroftJohn Slide
24
![Page 26: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/26.jpg)
Questions or Suggestions
Slide 25
![Page 27: Data structure tries](https://reader035.fdocuments.in/reader035/viewer/2022070523/58eda9861a28ab044c8b45dd/html5/thumbnails/27.jpg)
Thank you
Slide 26