• Aucun résultat trouvé

Table des suffixes

N/A
N/A
Protected

Academic year: 2022

Partager "Table des suffixes"

Copied!
36
0
0

Texte intégral

(1)

Table des suffixes

Thierry Lecroq

[email protected]

Laboratoire d’Informatique, de Traitement de l’Information et des Syst`emes (LITIS EA4108) Universit´e de Rouen Normandie, France

(2)

Plan

1 Introduction

2 Alphabet de taille born´ee

3 Table des LCP

4 Recherche d’un mot

5 Bibliographie

Thierry Lecroq (Rouen, France) Table des suffixes 2 / 36

(3)

Table des suffixes

Texte y∈A de longueurn Permutation des suffixes

SA:{0,1, . . . n−1} 7−→ {0,1, . . . n−1}telle que

y[SA[0]. . n−1]< y[SA[1]. . n−1]<· · ·< y[SA[n−1]. . n−1]

LCP (Longest Common Prefixes)

LCP[i] =|lcp(y[SA[i−1]. . n−1], y[SA[i]. . n−1])|

(4)

Table des suffixes

Exemple pour y=aataataata$

i SA[i] LCP[i]

0 11 0 $

1 10 0 a $

2 0 1 a a t a a t a a t t a $

3 3 6 a a t a a t t a $

4 6 3 a a t t a $

5 1 1 a t a a t a a t t a $

6 4 5 a t a a t t a $

7 7 2 a t t a $

8 9 0 t a $

9 2 2 t a a t a a t t a $

10 5 4 t a a t t a $

11 8 1 t t a $

Thierry Lecroq (Rouen, France) Table des suffixes 4 / 36

(5)

Plan

1 Introduction

2 Alphabet de taille born´ee

3 Table des LCP

4 Recherche d’un mot

5 Bibliographie

(6)

Algorithme

1 Deux tiers des positions idey sont tri´ees selon prem3(y[i . . n−1]): les positions de la forme i= 3koui= 3k+ 1avec kentier. Soit t[i]

le rang dei dans la liste tri´ee.

2 Les suffixes du motz=t[0]t[3]· · ·t[3k]· · ·t[1]t[4]· · ·t[3k+ 1]· · · sont tri´es r´ecursivement. Soit s[i]le rang du suffixe `a la position isur y dans la liste tri´ee (i= 3k ori= 3k+ 1) d´eriv´ee de la liste des suffixes tri´es dez.

3 Les suffixes y[j . . n−1], pour j de la forme3k+ 2, sont tri´es en utilisant la tables.

4 L’´etape finale consiste `a fusionner les listes obtenues aux ´etapes 2 et 3.

Thierry Lecroq (Rouen, France) Table des suffixes 6 / 36

(7)

D´ etails des ´ etapes

Etape 1´

Peut ˆetre ex´ecut´ee en temps lin´eaire en utilisant un radix sort

Etape 3´

Puisque l’ordre des suffixes y[j+ 1. . n−1]est connue pars, l’´etape 3 peut ˆetre r´ealis´ee en temps lin´eaire en utilisant un radix sort sur les couples (y[j], s[j+ 1]).

(8)

D´ etails des ´ etapes

Etape 4´

Comparer les suffixes aux positions i(i= 3k oui= 3k+ 1pour la premi`ere liste) etj (j= 3k+ 2pour la seconde liste) revient `a comparer des couples de la forme (y[i], s[i+ 1]) et (y[j], s[j+ 1]) si i= 3k ou de la forme(y[i]y[i+ 1], s[i+ 2]) et (y[j]y[j+ 1], s[j+ 2]) si i= 3k+ 1.

La fusion peut donc ˆetre r´ealis´ee en temps lin´eaire.

Thierry Lecroq (Rouen, France) Table des suffixes 8 / 36

(9)

Exemple

Le mot

i 0 1 2 3 4 5 6 7 8 9 10 11

y[i] a a t a a t a a t t a $

Les 2 ensembles de positions

P01={0,1,3,4,6,7,9,10} P2 ={2,5,8,11}

Etape 1´

imod3 = 0 imod 3 = 1

i 0 3 6 9 1 4 7 10

prem3(y[i . . n−1]) aat aat aat ta$ ata ata att a$

t[i] 1 1 1 4 2 2 3 0

(10)

Exemple

Etape 2´

z= 1 1 1 4 2 2 3 0 L01= (10,0,3,6,1,4,7,9)

i 0 3 6 9 1 4 7 10

s[i] 1 2 3 7 4 5 6 0

Thierry Lecroq (Rouen, France) Table des suffixes 10 / 36

(11)

Exemple

Etape 3´

imod 3 = 2

i 2 5 8 11

(y[i], s[i+ 1]) (t,2) (t,3) (t,7) ($,−1) L2 = (11,2,5,8)

(12)

Exemple

Etape 4´

imod3 = 0or 1 imod3 = 2

i 10 0 3 6 1 4 7 9 11 2 5 8

(y[i]y[i+ 1], s[i+ 2])(a,−1) (at,2)(at,3)(at,7) ($,−1)(ta,5)(ta,6)(tt,0) (y[i], s[i+ 1]) (a,4)(a,5)(a,6) (t,0)($,−1)(t,2) (t,3) (t,7)

La table des suffixes

i 0 1 2 3 4 5 6 7 8 9 10 11

SA[i] 11 10 0 3 6 1 4 7 9 2 5 8

Thierry Lecroq (Rouen, France) Table des suffixes 12 / 36

(13)

Pseudo-code

Tri-des-suffixes(y, n)

1 sin3alors

2 retournerpermutation des suffixes tri´es dey

3 sinonP01← {i: 0i < net(imod3 = 0ouimod3 = 1)}

4 sinmod3 = 0alors

5 P01P01∪ {n}

6 ttable des rangs des positionsideP01selonprem3(y[i . . n1])

7 zt[0]t[3]· · ·t[3k]· · ·t[1]t[4]· · ·t[3k+ 1]· · ·

8 qTri-des-suffixes(z,b2n/3c+ 1)

9 L01(3q[j]si0q[j]≤ bn/3c+ 1,3q[j] + 1sinon avecj= 0,1, . . . ,|z| −1)

10 stable des rangs des positions deL01

11 (s[n], s[n+ 1])(−1,−1)

12 L2liste des positionsj= 3k+ 2,3k+ 2< n tri´ees selon(y[j], s[j+ 1])

13 Lfusion deL01etL2 en utilisantComp

14 SApermutation des positions surycorrespondant `aL

(14)

Pseudo-code

Comp(i, j)

1 si imod3 = 0 alors

2 si(y[i], s[i+ 1])<(y[j], s[j+ 1]) alors 3 retourner −1

4 sinon retourner1

5 sinon si (y[i . . i+ 1], s[i+ 2])<(y[j . . j+ 1], s[j+ 2]) alors 6 retourner −1

7 sinon retourner1

Thierry Lecroq (Rouen, France) Table des suffixes 14 / 36

(15)

Complexit´ e

Proposition 1

Le temps d’ex´ecution de l’algorithme Tri-des-suffixesappliqu´e `a un mot de longueur nest O(n).

D´emonstration.

La r´ecursivit´e de l’algorithme (ligne 9) donne la relation de r´ecurrence T(n) =T(2n/3) +O(n)avec T(n) =O(1)pour n≤3puisque les autres lignes s’ex´ecutent en temps constant ou en tempsO(n).

Cette r´ecurrence a pour solution T(n) =O(n).

(16)

Plan

1 Introduction

2 Alphabet de taille born´ee

3 Table des LCP

4 Recherche d’un mot

5 Bibliographie

Thierry Lecroq (Rouen, France) Table des suffixes 16 / 36

(17)

Lemma 2

Soienti,j,i0 des positions sury pour lesquelsj=SA[i]etj−1 =SA[i0].

Alors LCP[i0]−1≤LCP[i].

(18)

Exemple

Thierry Lecroq (Rouen, France) Table des suffixes 18 / 36

(19)

D´emonstration.

Soit ule plus long pr´efixe commun `ay[j−1. . n−1]et `a son pr´ed´ecesseur dans l’ordre lexicographique y[k−1. . n−1]. Par d´efinition :LCP[i0] =|u|.

Si u est le mot vide le r´esultat est vrai carLCP[i]≥0.

Sinon,u peut s’´ecrirecv avecc=y[j−1]etv ∈A.

Le moty[j−1. . n−1] admet alors le pr´efixecvbpour une lettre b, et son pr´ed´ecesseur admet pour pr´efixecva pour une lettre atelle quea < b sauf s’il est ´egal `acv.

(20)

D´emonstration.

Donc, v est un pr´efixe commun `ay[j . . n−1]et y[k . . n−1].

De plus, y[k . . n−1], qui commence parva ou est ´egal `a v, est inf´erieur `a y[j . . n−1]qui commence par vb.

Donc LCP[i]qui est la longueur maximale des pr´efixes communs `a

y[j . . n−1]et `a son pr´ed´ecesseur dans l’ordre lexicographique ne peut pas ˆ

etre plus petit que|u|.

Nous avons donc LCP[i]≥ |u|=LCP[i0]−1.

Thierry Lecroq (Rouen, France) Table des suffixes 20 / 36

(21)

Algorithm

Def-LCP(y, n,SA)

1 pouri0`an1faire 2 ISA[SA[i]]i 3 `0

4 pourj0`an1faire 5 `max{0, `1}

6 iISA[j]

7 sii6= 0alors 8 j0SA[i1]

9 tantquej+` < netj0+` < net y[j+`] =y[j0+`]faire 10 ``+ 1

11 sinon`0 12 LCP[i]` 13 LCP[n]0 14 retournerLCP

(22)

Exemple

Thierry Lecroq (Rouen, France) Table des suffixes 22 / 36

(23)

Plan

1 Introduction

2 Alphabet de taille born´ee

3 Table des LCP

4 Recherche d’un mot

5 Bibliographie

(24)

Recherche dichotomique

La recherche d’un motx de longueurm dans y en utilisant le tableau des suffixes de y peut ˆetre r´ealis´ee par une simple recherche dichotomique.

L’algorithme Binary-Search(y, n,SA, x, m) suivant retourne : (−1,0)six < y[SA[0]. . n−1];

(n−1, n)si x > y[SA[n−1]. . n−1]; isi x est un pr´efixe de x[SA[i]. . n−1];

(i, i+ 1)si y[SA[i]. . n−1]< x < y[SA[i+ 1]. . n−1].

Thierry Lecroq (Rouen, France) Table des suffixes 24 / 36

(25)

D´ etails des ´ etapes

Binary-Search(y, n,SA, x, m) 1 `← −1

2 r ←n

3 tantque`+ 1< r faire 4 i← b(`+r)/2c

5 k← |lcp(x, y[SA[i]. . n−1])|

6 sik=m alors 7 retourner i

8 sinon six≤y[SA[i]. . n−1]alors

9 r ←i

10 sinon `←i 11 retourner (`, r)

(26)

Complexit´ e de la recherche dichotomique

La complexit´e temporelle de l’algorithme Binary-Search(y, n,SA, x, m) est O(m×logn).

Thierry Lecroq (Rouen, France) Table des suffixes 26 / 36

(27)

Analyse de la recherche dichotomique

Le nombre de couples(`, r)consid´er´es par l’algorithme

Binary-Search(y, n,SA, x, m) est born´e par2n+ 1: il y a n+ 1 couples de la forme (i, i+ 1)qui constituent les feuilles d’un arbre binaire donc il y au plus nnœuds internes.

(28)

Arbre de la recherche dichotomique

Thierry Lecroq (Rouen, France) Table des suffixes 28 / 36

(29)

Extension du tableau LCP

Il est donc possible d’´etendre le tableauLCP comme suit :

LCP[n+ 1 +i] = lcp(SA[`]. . n−1], y[SA[r]. . n−1]) o`u i=b(`+r)/2c.

La longueur du plus long pr´efixe commun entrey[SA[`]. . n−1]et y[SA[r]. . n−1]quand` < r−1est ´egale `a la valeur minimum parmi les LCP[i]o`u ` < i≤r.

Alors ces valeurs peuvent ˆetre calcul´ees par un appel `a l’algorithme Def-LCP(y,0, n−1,LCP).

(30)

Extension du tableau LCP

Def-LCP(y, `, r,LCP) . ` < r

1 si`+ 1 =r alors 2 retourner LCP[r]

3 sinon i← b(`+r)/2c

4 LCP[n+ 1 +i]←min{Def-LCP(y, `, i,LCP) Def-LCP(y, i, r,LCP)}

5 retourner LCP[n+ 1 +i]

Thierry Lecroq (Rouen, France) Table des suffixes 30 / 36

(31)

Recherche

Soient 3 entiers`, r, i tels que0≤` < i < r < n.

Si y[SA[`]. . n−1]< x < y[SA[r]. . n−1]soient

ld=|lcp(x, y[SA[`]. . n−1])|etlf=|lcp(x, y[SA[r]. . n−1])|satisfaisant ld≤lf.

Alors on a :

|lcp(y[SA[i]. . n−1], y[SA[r]. . n−1])|<lf

implique

y[SA[i]. . n−1]< x < y[SA[r]. . n−1]

et

|lcp(y[SA[i]. . n−1], y[SA[r]. . n−1])|>lf implique

y[SA[`]. . n−1]< x < y[SA[i]. . n−1].

(32)

Algorithme

Search(y, n,SA,LCP, x, m)

1 (`,ld)(−1,0)

2 (r,lf)(n,0)

3 tantque`+ 1< rfaire

4 i← b(`+r)/2c

5 gLcp(`, i)

6 hLcp(i, r)

7 sildhandh <lfalors

8 (`,ld)(i, h)

9 sinon sildlfandlf< halors

10 ri

11 sinon silfgandg <ldalors

12 (r,lf)(i, g)

13 sinon silfldandld< galors

14 `i

15 sinonkmax{ld,lf}

16 kk+|lcp(x[k . . m1], y[SA[i] + [k . . n1])|

17 sik=malors

18 retourneri

19 sinon six < y[SA[i]. . n1]alors

20 (r,lf)(i, k)

21 sinon(`,ld)(i, k)

22 retourner(`, r)

Thierry Lecroq (Rouen, France) Table des suffixes 32 / 36

(33)

Lcp

Lcp(i, j) =

(LCP[j] si j=i+ 1 LCP[n+ 1 +b(i+j)/2c] sinon.

(34)

Complexit´ e

La recherche peut ˆetre faite en temps O(m+ logn) avec l’algorithme Search(y, n,SA,LCP, x, m)

Thierry Lecroq (Rouen, France) Table des suffixes 34 / 36

(35)

Plan

1 Introduction

2 Alphabet de taille born´ee

3 Table des LCP

4 Recherche d’un mot

5 Bibliographie

(36)

Bibliographie

J. K¨arkk¨ainen and P. Sanders.

Simple linear work suffix array construction.

InProceedings of the 30th International Colloquium on Automata, Languages and Programming, number 2719 in Lecture Notes in Computer Science, pages 943–955, Eindhoven, The Netherlands, 2003. Springer-Verlag, Berlin.

T. Kasai, G. Lee, H. Arimura, S. Arikawa, and K. Park.

Linear-time longest-common-prefix computation in suffix arrays ans its application.

In A. Amir and G. M. Landau, editors,Proceedings of the 12th Annual Symposium on Combinatorial Pattern Matching, number 2089 in Lecture Notes in Computer Science, pages 169–180, Jerusalem, Israel, 2001. Springer-Verlag, Berlin.

D. K. Kim, J. S. Sim, H. Park, and K. Park.

Linear-time construction of suffix arrays.

In Ricardo A. Baeza-Yates, Edgar Ch´avez, and Maxime Crochemore, editors,Proceedings of the 14th Annual Symposium on Combinatorial Pattern Matching, volume 2676 ofLecture Notes in Computer Science, pages 186–199, Morelia, Michoc´an, Mexico, 2003. Springer-Verlag, Berlin.

P. Ko and S. Aluru.

Space efficient linear time construction of suffix arrays.

In Ricardo A. Baeza-Yates, Edgar Ch´avez, and Maxime Crochemore, editors,Proceedings of the 14th Annual Symposium on Combinatorial Pattern Matching, volume 2676 ofLecture Notes in Computer Science, pages 200–210, Morelia, Michoc´an, Mexico, 2003. Springer-Verlag, Berlin.

U. Manber and G. Myers.

Suffix arrays : a new method for on-line string searches.

SIAM J. Comput., 22(5) :935–948, 1993.

Thierry Lecroq (Rouen, France) Table des suffixes 36 / 36

Références

Documents relatifs

Our result is that the number of steps of LIME is bilinear, that is, linear in the number of β-steps and the size of the initial term, that are the two fundamental parameters in

When a straight Black/White bound- ary is digitized by point sampling, the grid points that are on the border between the black region (ξ D (i, j ) = 1) and the white one (ξ D (k, l)

For ANFIS based inferential models, when estimation/prediction accuracy is concerned, it is assumed that both the data used to train the model and the testing data to make

the ratio of water income (precipitation) and expenditure (runoff and evaporation) on the earth's surface for a long-term period is in equilibrium and is more or less

mountai basins but from watersheds with the areas not exceeding The computation is based on the equation of mean long-term annual water balance where normal annual runoff

In the context of foresl management in Nepal one would like to have a more comprehensive fina l discussion on institutional limitations acting upon the governmental

The volume then includes an article by Maria Teresa Sans Bertran (“Repertori i usos lingüístics d’un alumne intern d’origen marroquí d’un centre penitenciari

In Ricardo Baeza-Yates, Edgar Ch´ avez, and Maxime Crochemore, editors, Combinatorial Pattern Matching, vol- ume 2676 of Lecture Notes in Computer Science, pages 186–199.. [8] Pang