78
Recuperació de la informació rn Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Net ible Pattern Matching in Strings (2002) Gonzalo Navarro and Mathieu Raffinot rithms on strings (2001) M. Crochemore, C. Hancart and T. Lecroq ://www-igm.univ-mlv.fr/~lecroq/string/index

Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Embed Size (px)

Citation preview

Page 1: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Recuperació de la informació

•Modern Information Retrieval (1999)Ricardo-Baeza Yates and Berthier Ribeiro-Neto

•Flexible Pattern Matching in Strings (2002)Gonzalo Navarro and Mathieu Raffinot

•Algorithms on strings (2001)M. Crochemore, C. Hancart and T. Lecroq

•http://www-igm.univ-mlv.fr/~lecroq/string/index.html

Page 2: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

String Matching

String matching: definition of the problem (text,pattern) depends on what we have: text or patterns• Exact matching:

• Approximate matching:

• 1 pattern ---> The algorithm depends on |p| and || • k patterns ---> The algorithm depends on k, |p| and ||

• The text ----> Data structure for the text (suffix tree, ...)

• The patterns ---> Data structures for the patterns

• Dynamic programming • Sequence alignment (pairwise and multiple)

• Extensions • Regular Expressions

• Probabilistic search:

• Sequence assembly: hash algorithm

Hidden Markov Models

Page 3: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Index

1a. Part: Suffix trees Algorithms on strings, trees and sequences, Dan Gusfield Cambridge University Press

2a. Part: Suffix arrays Suffix-arrays: a new method for on-line

string searches, G. Myers, U. Manber

Page 4: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Suffix trees

Given string ababaas:

1: ababaas

2: babaas

3: abaas

4: baas

5: aas

6: as

7: s

as,3

s,6

as,5

s,7

as,4ba

baas,2

a

babaas,1

a

babaas,1

ba

baas,2

as,3

as,4

s,6

as,5

s,7

Suffixes:

What kind of queries?

Page 5: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Applications of Suffix trees

a

babaas,1as,3

ba

baas,2

as,4

s,6

as,5

s,7

1. Exact string matching

…………………………

• Does the sequence ababaas contain any ocurrence of patterns abab, aab, and ab?

Page 6: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string …………………………......

P1: the leaves of suffixes from have been inserted

and the suffix-tree

…...

Invariant Properties:

Page 7: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string ababaabbs

ababaabbs,1

Page 8: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string ababaabbs

babaabbs,2

ababaabbs,1

Page 9: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string ababaabbs

babaabbs,2

ababaabbs,1ababaabbs,1

Page 10: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string ababaabbs

babaabbs,2

ababaabbs,1

abbs,3

Page 11: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string ababaabbs

babaabbs,2

ababaabbs,1

abbs,3

ba

baabbs,2

Page 12: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string ababaabbs

ababaabbs,1

abbs,3

ba

baabbs,2

abbs,4

Page 13: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string ababaabbs

ababaabbs,1

abbs,3

abbs,4ba

baabbs,2

abbs,4

abbs,3ba

a

baabbs,1

Page 14: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string ababaabbs

abbs,4ba

baabbs,2

abbs,4

abbs,3ba

a

baabbs,1

abbs,5

Page 15: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string ababaabbs

abbs,4ba

baabbs,2

abbs,4

abbs,3ba

a

baabbs,1

abbs,5

Page 16: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string ababaabbs

abbs,4

ba

ba

baabbs,2

abbs,4

a abbs,5

b

a abbs,3

baabbs,1

Page 17: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string ababaabbs

abbs,4ba

baabbs,2

abbs,4

a abbs,5

b

a abbs,3

baabbs,1

bs,6

Page 18: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string ababaabbs

abbs,4ba

baabbs,2

abbs,4

a abbs,5

b

a abbs,3

baabbs,1

bs,6

Page 19: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string ababaabbs

a abbs,5

b

a abbs,3

baabbs,1

bs,6

a

baabbs,2

b

abbs,4

bs,7

Page 20: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string ababaabbs

a abbs,5

b

a abbs,3

baabbs,1

bs,6

a

baabbs,2

b

abbs,4

bs,7

s,7

Page 21: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string ababaabbs

a abbs,5

b

a abbs,3

baabbs,1

bs,6

a

baabbs,2

b

abbs,4

bs,7

s,7

s,7

Page 22: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Generalizad suffix tree

The suffix tree of many strings …

and it is the suffix tree of the concatenation of strings.

the generalized suffix tree of ababaabb and aabaat …

is the suffix tree of ababaabαaabaatβ, :

is called the generalized suffix tree …

For instance,

Page 23: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Generalizad suffix tree

a abbα,5

b

a abbα,3

baabbα,1

bα,6

a

baabbα,2

b

abbα,4

bα,7

α,7

α,7

Given the suffix tree of ababaabα :

Construction of the suffix tree of ababaabbαaabaaβ :

Page 24: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Generalizad suffix tree

a abbα,5

b

a abbα,3

baabbα,1

bα,6

a

baabbα,2

b

abbα,4

bα,7

α,7

α,7

Construction of the suffix tree of ababaabbαaabaaβ :

Page 25: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Generalizad suffix tree

Construction of the suffix tree of ababaabbαaabaaβ :

a bα,5

b

a abbα,3

baabbα,1

bα,6

a

baabbα,2

b

abbα,4

bα,7

α,7

α,7

abaaβ,1

Page 26: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Generalizad suffix tree

Construction of the suffix tree of ababaabbαaabaaβ :

a bα,5

b

a abbα,3

baabbα,1

bα,6

a

baabbα,2

b

abbα,4

bα,7

α,7

α,7

abaaβ,1

Page 27: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Generalizad suffix tree

a bα,5

b

a bbα,3

baabbα,1

bα,6

a

baabbα,2

b

abbα,4

bα,7

α,7

α,7

abaaβ,1

aβ,2

Construction of the suffix tree of ababaabbαaabaaβ :

Page 28: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Generalizad suffix tree

a bα,5

b

a bbα,3

baabbα,1

bα,6

a

baabbα,2

b

abbα,4

bα,7

α,7

α,7

abaaβ,1

aβ,2

Construction of the suffix tree of ababaabbαaabaaβ :

Page 29: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Construction of the suffix tree of ababaabbαaabaaβ :

Generalizad suffix tree

a bα,5

b

a bbα,3

baabbα,1

bα,6

a

baabbα,2

b

bbα,4

bα,7

α,7

α,7

abaaβ,1

aβ,2

aβ,3

Page 30: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Construction of the suffix tree of ababaabbαaabaaβ :

Generalizad suffix tree

a bα,5

b

a bbα,3

baabbα,1

bα,6

a

baabbα,2

b

bbα,4

bα,7

α,7

α,7

abaaβ,1

aβ,2

aβ,3

Page 31: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Generalizad suffix tree

abα,5

b

a bbα,3

baabbα,1

bα,6

a

baabbα,2

b

bbα,4

bα,7

α,7

α,7

baaβ,1

aβ,2

aβ,3

a

β,4

Construction of the suffix tree of ababaabbαaabaaβ :

Page 32: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Generalizad suffix tree

abα,5

b

a bbα,3

baabbα,1

bα,6

a

baabbα,2

b

bbα,4

bα,7

α,7

α,7

baaβ,1

aβ,2

aβ,3

a

β,4

Construction of the suffix tree of ababaabbαaabaaβ :

Page 33: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Generalizad suffix tree

abα,5

b

a bbα,3

baabbα,1

bα,6

a

baabbα,2

b

bbα,4

bα,7

α,7

α,7

baaβ,1

aβ,2

aβ,3

a

β,4β,4

Construction of the suffix tree of ababaabbαaabaaβ :

Page 34: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Generalizad suffix tree

abα,5

b

a bbα,3

baabbα,1

bα,6

a

baabbα,2

b

bbα,4

bα,7

α,7

α,7

baaβ,1

aβ,2

aβ,3

a

β,4β,4

Construction of the suffix tree of ababaabbαaabaaβ :

Page 35: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Generalizad suffix tree

abα,5

b

a bbα,3

baabbα,1

bα,6

a

baabbα,2

b

bbα,4

bα,7

α,7

α,7

baaβ,1

aβ,2

aβ,3

a

β,4β,4β,4

Construction of the suffix tree of ababaabbαaabaaβ :

Page 36: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Generalizad suffix tree

a bα,5

ba bbα,3

baabbα,1

bα,6

a

baabbα,2

b

bbα,4

bα,7

α,7

α,7

baaβ,1

aβ,2

a β,3

aβ,4β,4

β,4

Generalized suffix tree of ababaabbαaabaaβ :

Page 37: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Applications of Generalized Suffix trees

1. The substring problem for a database of strings DB• Does the DB contain any ocurrence of patterns abab, aab, and ab?

a bα,5

ba bbα,3

baabbα,1

bα,6

a

baabbα,2

b

bbα,4

bα,7

α,7

α,7

baaβ,1

aβ,2

a β,3

aβ,4β,4

β,4

Page 38: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Applications of Generalized Suffix trees

2. The longest common substring of two strings

a bα,5

ba bbα,3

baabbα,1

bα,6

a

baabbα,2

b

bbα,4

bα,7

α,7

α,7

baaβ,1

aβ,2

a β,3

aβ,4β,4

β,4

Page 39: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Applications of Generalized Suffix trees

3. Finding MUMs.

a bα,5

ba bbα,3

baabbα,1

bα,6

a

baabbα,2

b

bbα,4

bα,7

α,7

α,7

baaβ,1

aβ,2

a β,3

aβ,4β,4

β,4

Page 40: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Quadratic insertion algorithm

Given the string …………………………......

P1: the leaves of suffixes from have been inserted

and the suffix-tree

…...

Invariant Properties:

Page 41: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm

Given the string …………………………......

P2: the string is the longest string that can be spelt through the tree.

P1: the leaves of suffixes from have been inserted

and the suffix-tree

…...

Invariant Properties:

Page 42: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

Given the string ababaababb...

ba

baababab...,2

a ababab...,5

ba ababab...,3

baababab...,1ababab...,4

Page 43: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

Given the string ababaababb...

ba

baababab...,2

a ababab...,5

ba ababab...,3

baababab...,1ababab...,4

6 7 8

Page 44: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

ba

baababb...,2

a ababb...,5

ba ababb...,3

baababb...,1ababb...,4

6 7 8Given the string ababaababb...

Page 45: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

ba

baababb...,2

a ababb...,5

ba ababb...,3

baababb...,1ababb...,4

6 7 89Given the string ababaababb...

Page 46: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

ba ababb...,3

baababb...,1

ba

baababb...,2

ababb...,4

Given the string ababaababb...

6 7 89

baababb...,1b

b...,6

ababb...,1

Page 47: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

ba ababb...,3

ba

baababb...,2

ababb...,4

Given the string ababaababb...

7 89

b

b...,6

ababb...,1

Page 48: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

ba ababb...,3

ba

baababb...,2

ababb...,4

Given the string ababaababb...

7 89

b

b...,6

ababb...,1

a

Page 49: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

ba ababb...,3

ba

baababb...,2

ababb...,4

Given the string ababaababb...

7 89

b

b...,6

ababb...,1

Page 50: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

ba ababb...,3

ba

baababb...,2

ababb...,4

Given the string ababaababb...

7 89

b

b...,6

ababb...,1

baababb...,2b aababb...,2

Page 51: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

ba ababb...,3

ba

baababb...,2

ababb...,4

Given the string ababaababb...

7 8…

b

b...,6

ababb...,1

baababb...,2b

b...,7

aababb...,2

Page 52: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

ba ababb...,3

ba ababb...,4

Given the string ababaababb...

89

b

b...,6

ababb...,1

b

b...,7

aababb...,2

Page 53: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

ba ababb...,3

ba ababb...,4

Given the string ababaababb...

89

b

b...,6

ababb...,1

b

b...,7

aababb...,2

Page 54: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

ba ababb...,3

ba ababb...,4

Given the string ababaababb...

89

b

b...,6

ababb...,1

b

b...,7

aababb...,2

Page 55: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

b

ba ababb...,4

Given the string ababaababb...

89

ababb...,3

b

b...,6

ababb...,1

b

b...,7

aababb...,2

a

Page 56: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

b

ba ababb...,4

Given the string ababaababb...

89

ababb...,3

b

b...,6

ababb...,1

b

b...,7

aababb...,2

a

b...,8

Page 57: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

b

ba ababb...,4

Given the string ababaababb...

9

ababb...,3

b

b...,6

ababb...,1

b

b...,7

aababb...,2

a

b...,8

Page 58: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

b

ba ababb...,4

Given the string ababaababb...

9

ababb...,3

b

b...,6

ababb...,1

b

b...,7

aababb...,2

a

b...,8

Page 59: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

b

b ababb...,4

Given the string ababaababb... 9

ababb...,3

b

b...,6

ababb...,1

b

b...,7

aababb...,2

a

b...,8

a

Page 60: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

b

b ababb...,4

Given the string ababaababb... 9

ababb...,3

b

b...,6

ababb...,1

b

b...,7

aababb...,2

a

b...,8

a

b...,9

Page 61: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

b

b ababb...,4

Given the string ababaababb... 9

ababb...,3

b

b...,6

ababb...,1

b

b...,7

aababb...,2

a

b...,8

a

b...,9

Page 62: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm: example

a ababb...,5

b

b ababb...,4

Given the string ababaababb...

9

ababb...,3

b

b...,6

ababb...,1

b

b...,7

aababb...,2

a

b...,8

a

b...,9

Page 63: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm

Given the string ababaababs

ababaababs,1

Page 64: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm

Given the string ababaababs

ababaababs,1

babaababs,2

Page 65: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm

Given the string ababaababs

ababaababs,1

babaababs,2

Page 66: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm

Given the string ababaababs

ababaababs,1

babaababs,2

Page 67: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm

Given the string ababaababs

ababaababs,1

babaababs,2

Page 68: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm

Given the string ababaababs

ababaababs,1

babaababs,2

ababaababs,1

Page 69: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm

Given the string ababaababs

babaababs,2

ababaababs,1

ababs,3

ba

baababs,2

Page 70: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm

Given the string ababaababs

ababaababs,1

ababs,3

ba

baababs,2

ababs,4

ababs,3ba

a

baababs,1

Page 71: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Linear insertion algorithm

Given the string ababaababs

ba

baababs,2

ababs,4

ababs,3ba

a

baababs,1

ababs,5

Page 72: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Index

1a. Part: Suffix trees Algorithms on strings, trees and sequences, Dan Gusfield Cambridge University Press

2a. Part: Suffix arrays Suffix-arrays: a new method for on-line

string searches, G. Myers, U. Manber

Page 73: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Suffix arrays

Given string ababaa#:

1: ababaa#

2: babaa#

3: abaa#

4: baa#

5: aa#

6: a#

7: #

Suffixes: … but lexicographically sorted

1: ababaa#

2: babaa#

3: abaa#

4: baa#

5: aa#6: a#1: #1

234567

Which is the cost? O(n log(n))

Page 74: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Applications of suffix arrays

1. Exact string matching• Does the sequence ababaas contain any ocurrence of patterns abab, aab, and ab?

1: ababaa#

2: babaa#

3: abaa#

4: baa#

5: aa#6: a#1: #1

234567

Binary search

Page 75: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Search with cost O(log(n) |P|) Query:

Invariant Properties:

P1: α < query ≤ β α

β

12… …

n

Suffix array

Page 76: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Search with cost O(log(n) |P|) Query:

Invariant Properties:

P1: α < query ≤ β α

β

γ

Algorithm:

12… …

n

Suffix array

If γ<query then α = γ

else β = γ

Cost: O(log(n) |P|)

Can it be improved to … O(log(n)+|P|) ?

Page 77: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Fast search with cost O(log(n)+|P|) Query:

Invariant Properties:

P1: α < query ≤ β α

β

12… …

n

Suffix array

P2: matches pref( query)

Page 78: Recuperació de la informació Modern Information Retrieval (1999) Ricardo-Baeza Yates and Berthier Ribeiro-Neto Flexible Pattern Matching in Strings (2002)

Fast search with cost O(log(n)+|P|) Query:

Invariant Properties:

P1: α < query ≤ β α

β

γAlgorithm:

12… …

n

Suffix array

P2: matches pref( query)

If x<y then α = γ

x>y then β = γ

x=y then …fi

x

y