![Page 1: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/1.jpg)
String Data Structures
![Page 2: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/2.jpg)
Why do we need string data structures?
![Page 3: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/3.jpg)
Why do we need string data structures?
![Page 4: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/4.jpg)
Why do we need string data structures?
![Page 5: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/5.jpg)
Why do we need string data structures?
![Page 6: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/6.jpg)
String Data StructuresBefore Computers
![Page 7: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/7.jpg)
Can binary search for a word in time O(log n).
Can interpolation search in average time O(log log n).
![Page 8: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/8.jpg)
Array accesses take time O(1).
Jump to the drawer, then do an O(d) lookup, whered is the number of elements in the drawer.
![Page 9: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/9.jpg)
Miriam-Webster’s physical “Backward Index:”All English words, written in reverse, in sorted order.
Why would you want this?
![Page 10: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/10.jpg)
Find all words ending in “iatrics.”
Time required: O(log n + k).
![Page 11: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/11.jpg)
String Data StructuresWith Computers
![Page 12: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/12.jpg)
aaboutad
adageadagiobarbardbarnbedbetbetacancanecat
dikdikdiktat
![Page 13: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/13.jpg)
aaboutad
adageadagio
barbardbarnbedbetbeta
cancanecat
dikdikdiktat
a b c d
![Page 14: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/14.jpg)
aaboutad
adageadagio
barbardbarnbedbetbeta
cancanecat
dikdikdiktat
a b c d
The double circle means
“this is a word.”
The double circle means
“this is a word.”
![Page 15: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/15.jpg)
aboutad
adageadagio
barbardbarnbedbetbeta
cancanecat
dikdikdiktat
a b c d
Because we’ve remembered that “a” is a word, we’ll remove it from our list.
Because we’ve remembered that “a” is a word, we’ll remove it from our list.
![Page 16: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/16.jpg)
aboutad
adageadagio
barbardbarnbedbetbeta
cancanecat
dikdikdiktat
a b c d
![Page 17: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/17.jpg)
about
barbardbarnbedbetbeta
cancanecat
dikdikdiktat
a b c d
b d
adadageadagio
![Page 18: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/18.jpg)
about
barbardbarnbedbetbeta
cancanecat
dikdikdiktat
a b c d
b d
adadageadagio
![Page 19: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/19.jpg)
about
barbardbarnbedbetbeta
cancanecat
dikdikdiktat
a b c d
b d
adadageadagio
![Page 20: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/20.jpg)
about
barbardbarnbedbetbeta
cancanecat
dikdikdiktat
a b c d
b d
adageadagio
![Page 21: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/21.jpg)
about barbardbarn
cancanecat
dikdikdiktat
a b c d
b d
adageadagio
a e
bedbetbeta
![Page 22: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/22.jpg)
about barbardbarn
cancanecat
dikdikdiktat
a b c d
b d
adageadagio
a e
bedbetbeta
![Page 23: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/23.jpg)
about
barbardbarn
cancanecat
dikdikdiktat
a b c d
b d
adageadagio
a e
bedbetbeta
r
![Page 24: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/24.jpg)
about
barbardbarn
cancanecat
dikdikdiktat
a b c d
b d
adageadagio
a e
bedbetbeta
r
![Page 25: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/25.jpg)
about
bardbarn
cancanecat
dikdikdiktat
a b c d
b d
adageadagio
a e
bedbetbeta
r
![Page 26: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/26.jpg)
about
bard
cancanecat
dikdikdiktat
a b c d
b d
adageadagio
a e
bedbetbeta
r
d n
barn
![Page 27: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/27.jpg)
about
bard
cancanecat
dikdikdiktat
a b c d
b d
adageadagio
a e
bedbetbeta
r
d n
barn
![Page 28: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/28.jpg)
about
cancanecat
dikdikdiktat
a b c d
b d
adageadagio
a e
bedbetbeta
r
d n
![Page 29: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/29.jpg)
about cancanecat
dikdikdiktat
a b c d
b d
adageadagio
a e
bedbetbeta
r
d n
a
![Page 30: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/30.jpg)
about cancanecat
dikdikdiktat
a b c d
b d
adageadagio
a e
bedbetbeta
r
d n
a
![Page 31: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/31.jpg)
about
cancane
dikdikdiktat
a b c d
b d
adageadagio
a e
bedbetbeta
r
d n
a
n t
cat
![Page 32: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/32.jpg)
about
cancane
dikdikdiktat
a b c d
b d
adageadagio
a e
bedbetbeta
r
d n
a
n t
cat
![Page 33: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/33.jpg)
about
cane
dikdikdiktat
a b c d
b d
adageadagio
a e
bedbetbeta
r
d n
a
n t
![Page 34: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/34.jpg)
a b c d
b
o
u
t
d
a
g
e i
o
a
r
d n
e
d t
a
a
n
e
t
i
k
a
t
i
k
d t
![Page 35: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/35.jpg)
a b c d
b
o
u
t
d
a
g
e i
o
a
r
d n
e
d t
a
a
n
e
t
i
k
a
t
i
k
d t
This data structure is called a trie. It’s pronounced “try.” It
comes from the word “retrieval.” This is a terrible pun and we’re
stuck with it forever.
This data structure is called a trie. It’s pronounced “try.” It
comes from the word “retrieval.” This is a terrible pun and we’re
stuck with it forever.
![Page 36: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/36.jpg)
Using a Trie
![Page 37: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/37.jpg)
![Page 38: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/38.jpg)
![Page 39: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/39.jpg)
![Page 40: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/40.jpg)
![Page 41: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/41.jpg)
![Page 42: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/42.jpg)
![Page 43: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/43.jpg)
![Page 44: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/44.jpg)
![Page 45: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/45.jpg)
![Page 46: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/46.jpg)
![Page 47: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/47.jpg)
![Page 48: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/48.jpg)
![Page 49: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/49.jpg)
![Page 50: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/50.jpg)
![Page 51: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/51.jpg)
![Page 52: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/52.jpg)
![Page 53: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/53.jpg)
![Page 54: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/54.jpg)
![Page 55: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/55.jpg)
![Page 56: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/56.jpg)
![Page 57: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/57.jpg)
![Page 58: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/58.jpg)
![Page 59: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/59.jpg)
![Page 60: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/60.jpg)
![Page 61: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/61.jpg)
![Page 62: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/62.jpg)
![Page 63: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/63.jpg)
![Page 64: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/64.jpg)
![Page 65: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/65.jpg)
![Page 66: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/66.jpg)
![Page 67: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/67.jpg)
![Page 68: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/68.jpg)
![Page 69: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/69.jpg)
![Page 70: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/70.jpg)
![Page 71: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/71.jpg)
![Page 72: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/72.jpg)
![Page 73: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/73.jpg)
![Page 74: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/74.jpg)
![Page 75: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/75.jpg)
![Page 76: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/76.jpg)
![Page 77: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/77.jpg)
![Page 78: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/78.jpg)
![Page 79: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/79.jpg)
![Page 80: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/80.jpg)
![Page 81: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/81.jpg)
![Page 82: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/82.jpg)
![Page 83: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/83.jpg)
![Page 84: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/84.jpg)
![Page 85: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/85.jpg)
![Page 86: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/86.jpg)
![Page 87: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/87.jpg)
![Page 88: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/88.jpg)
![Page 89: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/89.jpg)
![Page 90: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/90.jpg)
![Page 91: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/91.jpg)
![Page 92: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/92.jpg)
![Page 93: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/93.jpg)
![Page 94: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/94.jpg)
![Page 95: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/95.jpg)
![Page 96: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/96.jpg)
![Page 97: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/97.jpg)
![Page 98: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/98.jpg)
![Page 99: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/99.jpg)
![Page 100: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/100.jpg)
![Page 101: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/101.jpg)
![Page 102: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/102.jpg)
![Page 103: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/103.jpg)
![Page 104: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/104.jpg)
![Page 105: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/105.jpg)
![Page 106: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/106.jpg)
![Page 107: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/107.jpg)
![Page 108: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/108.jpg)
![Page 109: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/109.jpg)
![Page 110: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/110.jpg)
Other Operations on Tries
● Find all strings in the trie that start with a given prefix.● How might you implement this?
● Print all strings in sorted order.● How might you implement this?
● Find the first string that’s alphabetically before or after another.● How might you implement this?
![Page 111: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/111.jpg)
A Useful Perspective
![Page 112: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/112.jpg)
...an empty list,represented bynullptr, or...
a single linked listcell that points...
... at another linked list.
A Linked List is Either...
![Page 113: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/113.jpg)
A Binary Search Tree Is Either...an empty tree, represented by nullptr, or...
x
<x >x
... a single node,whose left subtree
is a BST of smaller values ...
... and whose right subtree is a BST of larger values.
![Page 114: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/114.jpg)
A Trie is Either...an empty trie, represented by nullptr, or...
![Page 115: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/115.jpg)
A Trie is Either...an empty trie, represented by nullptr, or...
q x
…
z
a single node, which might be marked as a
word...
... with some number of child tries labeled by
letters.…
![Page 116: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/116.jpg)
struct Cell { Type value; Cell* next;};
struct Node { Type value; Node* left; Node* right;};
struct Name? {
/* ? */
};
Singly-Linked List Binary Search Tree Trie
Assignment 6: Think through these design
decisions!
![Page 117: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/117.jpg)
Time-Out for Announcements!
![Page 118: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/118.jpg)
![Page 119: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/119.jpg)
Assignment 6
● Assignment 6 (MiniBrowser) goes out today. It’s due one week from Friday at the start of class.● Play around with linked lists and tree data
structures!● Build integral pieces of a larger system!● See why all this stuff matters.
● YEAH hours will be held today at 5:00PM in 380-380Y. Slides will be posted.
![Page 120: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/120.jpg)
Back to CS106B!
![Page 121: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/121.jpg)
Twists on Tries(a sneak peek of beautiful CS concepts!)
![Page 122: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/122.jpg)
Twist: Finite Automata
![Page 123: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/123.jpg)
a b c d
b
o
u
t
d
a
g
e i
o
a
r
d n
e
d t
a
a
n
e
t
i
k
a
t
i
k
d t
General rule to look up a string:
1. Start at some node.
2. Follow links based on theletters you read.
3. The string is there if youdon’t get stuck and land at adouble circle.
General rule to look up a string:
1. Start at some node.
2. Follow links based on theletters you read.
3. The string is there if youdon’t get stuck and land at adouble circle.
![Page 124: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/124.jpg)
g r a n dm a
p astart
grandmagrandpagreat-grandmagreat-great-grandpagreat-great-great-great-grandpa…
Breaking the Rules
![Page 125: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/125.jpg)
g r a n dm a
p astart
e
at
-
This isn’t a tree, but we can still follow the same
rules!
This isn’t a tree, but we can still follow the same
rules!
grandmagrandpagreat-grandmagreat-great-grandpagreat-great-great-great-grandpa…
Breaking the Rules
![Page 126: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/126.jpg)
start * //
a *a
*
/
What sorts of strings does this weird
thingy contain?
What sorts of strings does this weird
thingy contain?
/*aaaa*//***aaaa***//*aaa*aaa*//*********/
…
![Page 127: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/127.jpg)
Finite Automata
● A finite automaton is a generalization of a trie.
● It’s not necessarily a tree; there can be circular paths, places where branches come together, etc.
● Finite automata power many compilers and pattern-matching tools.
● Want to learn more? Take CS103!
![Page 128: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/128.jpg)
Twist: Suffix Trees
![Page 129: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/129.jpg)
Cancer cells often have multiple repeated copies the same gene.
Given a cancer genome (length ~3,000,000,000 letters)and a gene, count the occurrences of that gene.
![Page 130: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/130.jpg)
A Fundamental Theorem
● The fundamental theorem of stringology says that, given two strings w and x, that
w is a substring of xif and only if
w is a prefix of a suffix of x
f l i b b e r t i i b b eg t
b e
![Page 131: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/131.jpg)
A Fundamental Theorem
● The fundamental theorem of stringology says that, given two strings w and x, that
w is a substring of xif and only if
w is a prefix of a suffix of x
f l i b
b e
b e r t i i b b eg t
![Page 132: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/132.jpg)
A Fundamental Theorem
● The fundamental theorem of stringology says that, given two strings w and x, that
w is a substring of xif and only if
w is a prefix of a suffix of x
f l i b
b e
b e r t i i b b eg t
![Page 133: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/133.jpg)
A Fundamental Theorem
● The fundamental theorem of stringology says that, given two strings w and x, that
w is a substring of xif and only if
w is a prefix of a suffix of x
f l i b b e r t i i b b eg t
b e
![Page 134: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/134.jpg)
A Fundamental Theorem
● The fundamental theorem of stringology says that, given two strings w and x, that
w is a substring of xif and only if
w is a prefix of a suffix of x
f l i b b e r t i i bg
b e
b e t
![Page 135: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/135.jpg)
A Fundamental Theorem
● The fundamental theorem of stringology says that, given two strings w and x, that
w is a substring of xif and only if
w is a prefix of a suffix of x
f l i b b e r t i i bg
b e
b e t
![Page 136: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/136.jpg)
A Fundamental Theorem
● The fundamental theorem of stringology says that, given two strings w and x, that
w is a substring of xif and only if
w is a prefix of a suffix of x● Recall: Tries make it really easy to check
if something is a prefix of any number of strings.
● Idea: Store all the suffixes of a string in a trie!
![Page 137: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/137.jpg)
e n o s
o
n
s
e
s
n
e
s
n
e
s
n
e
s
e
e
n
e
s
n
e
s
n
e
s
nonsense
![Page 138: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/138.jpg)
Suffix Trees
● With a lot of creativity, it’s possible to compress the trie shown earlier to have only O(n) nodes.
● This is called a suffix tree and is a workhorse of a data structure.
● Want to learn more? Take CS166!
![Page 139: String Data Structures - Stanford University...says that, given two strings w and x, that w is a substring of x if and only if w is a prefix of a suffix of x Recall: Tries make it](https://reader034.vdocuments.site/reader034/viewer/2022050400/5f7df4dce206fe232d520e51/html5/thumbnails/139.jpg)
Next Time
● The Magic of Hash Functions● A beautiful mathematical idea with
incredible power.● Hash Tables
● Surpassing BST performance!