2013.11.26.linear time rewriting algorithm.postertheorem [nong, 2013] suffix...

21
Linear time in-place algorithm for suffix and related arrays 九州大学 後藤啓介 1

Upload: others

Post on 16-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

Linear time in-place algorithm for suffix and related arrays

九州大学後藤啓介

1

Page 2: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

はじめに,Suffix Arrayとは✦ 文字列Tの全てのsuffixを辞書順にソートして保存した配列

(suffixの開始位置の並びを保存)

2

i SA[i] T[SA[i]..N] 1 3 aaacatat 2 4 aacatat 3 1 acaaacatat4 5 acatat 5 9 at 6 7 atat 7 2 caaacatat 8 6 catat 9 10 t 10 8 tat

T = acaaacatat

[Manber and Myers, 1993]

Page 3: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

Suffix Arrayの応用✦ SAと補助配列,類似するデータ構造を使用することで様々な文字列処理を高速化可能

3

検索

SA LCP+

LZ77圧縮

NSV(PSV)

q-gram頻度

SA(Φ)

LCP(PLCP)

+

etc....

Page 4: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

本発表の目標✦ SAやそれに類似する配列(Φ, LCP, NSV, ...)をより省領域に求めたいできれば入力文字列T(N=|T|)と作りたい配列のみのサイズで(文字を1 byte, 整数を4 bytesとすると,5N bytesのみ)

4

*本発表ではアルファベットサイズを定数とします

Theorem [Nong, 2013]

Suffix Arrayをin-placeに線形時間構築可能

SAについてはin-place構築可能であることが知られているΦ, LCP(PLCP), NSV(PSV)のin-place計算を考える

Page 5: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

研究結果

5

旧手法 新手法Φ 9N bytes 5N bytes

NSV(PSV) 9N bytes 5N bytes

PLCP 9N bytes 5N bytes

LCP 6~10N bytes 5N bytes + 2N bits

in-place

in-place

in-place

[2] [Crochemore and Ilie, 2008][1] [Kärkkäinen+, 2009]

[3] [Manzini, 2008]

[1]

[1]

[2]

[3]

✦ Φ,NSV(PSV), PLCP配列がin-place構築可能なことを示したΦ配列を書き換えることでin-place構築を実現

Page 6: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

Φ 配列

6

i Φ[i] SA[i] T[SA[i]..N] 1 4 3 aaacatat 2 7 4 aacatat 3 0 1 acaaacatat4 3 5 acatat 5 1 9 at 6 2 7 atat 7 9 2 caaacatat 8 10 6 catat 9 5 10 t 10 6 8 tat

T = acaaacatat

Suffix Arrayのpredecessor link,辞書の順序関係をテキスト順に保持した配列Φ[SA[i]] = SA[i-1] (i > 1), Φ[SA[1]] = N

[Kärkkäinen+, 2009]

SAの値を逆順に得ることが出来る

Page 7: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

✦ Φ配列を起点とすることで様々な配列がin-place構築可能となる

7

Theorem

Φ配列を線形時間でin-placeに構築可能

LemmaΦ配列からNSV(PSV)配列に線形時間でin-placeに書き換え可能

Lemma [Kärkkäinen+, 2009]

Φ配列からPLCP配列に線形時間でin-placeに書き換え可能

研究内容1: Φ配列のin-place構築

Page 8: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

8

TheoremNSV(PSV)配列を線形時間でin-placeに構築可能

Theorem

PLCP配列を線形時間でin-placeに構築可能

✦ Φ配列を起点とすることで様々な配列がin-place構築可能となる

Theorem

Φ配列を線形時間でin-placeに構築可能

研究内容1: Φ配列のin-place構築

Page 9: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

NSV, PSV配列

9

i PSV[i] NSV[i] SA[i] T[SA[i]..N] 1 -1 -1 3 aaacatat 2 1 -1 4 aacatat 3 -1 1 1 acaaacatat4 3 1 5 acatat 5 1 2 9 at 6 2 -1 7 atat 7 5 2 2 caaacatat 8 6 -1 6 catat 9 5 7 10 t 10 6 -1 8 tat

T = acaaacatat

各suffixの辞書順のpredecessor, successorのsuffixを保持した配列PSV[i] = SA[j1], j1 = maxk(k < SA-1[i] and SA[k] < i)NSV[i] = SA[j2], j2 = mink(k > SA-1[i] and SA[k] < i)上記のj1, j2がなければPSV[i] = -1, NSV[i] = -1

NSV

PSV

[Crochemore and Ilie, 2008]

Page 10: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

PSV, NSV配列の線形時間構築

10

Lemma [Crochemore and Ilie, 2008]

SA[i]を右から左(or 左から右)に読むことで全てのPSV(SA[i])とNSV(SA[i])を線形時間で計算可能

12 7 15 4

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

PSVNSV

SA

Page 11: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

11

12 7 15 4

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

ΦPSV

SA

NSVに書き換え

✦ Φ配列を使いSA[i]を右から左に得ることが出来る✦ 読み込んだΦ[SA[i]]は二度と読まれない

Observation

順序関係が同じため,Φ[SA[i]]にNSV(SA[i])を格納することが可能

Page 12: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

LCP配列

12

T = acaaacatat

SA上の隣接するsuffix間のLongest Common Prefixの長さを保持した配列For i > 1, LCP[i] = lcp(T[SA[i-1]..N], T[SA[i]..N])

(lcp(s1, s2): s1, s2のLCPの長さ)

i LCP[i] SA[i] T[SA[i]..N] 1 3 aaacatat 2 2 4 aacatat 3 1 1 acaaacatat4 3 5 acatat 5 1 9 at 6 2 7 atat 7 0 2 caaacatat 8 2 6 catat 9 0 10 t 10 1 8 tat

[Kasai, Lee+, 2001]

Page 13: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

PLCP配列

13

T = acaaacatat

LCP配列をテキスト順に保存した配列PLCP[SA[i]] = LCP[i]

i LCP[i] SA[i] T[SA[i]..N] 1 1 3 aaacatat 2 0 2 4 aacatat 3 1 1 acaaacatat4 2 3 5 acatat 5 3 1 9 at 6 2 2 7 atat 7 2 0 2 caaacatat 8 1 2 6 catat 9 1 0 10 t 10 0 1 8 tat

[Kärkkäinen+, 2009][Sadakane, 2002]

Page 14: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

PLCP配列の線形時間構築

14

1. l = 02. For i = 1 to N3. while T[i + l] = T[Φ[i] + l]4. l ← l+15. PLCP[i] = l6. l = max(l-1, 0)

Theorem [Kärkkäinen+ 2009]

PLCP(LCP)配列を9N bytesで線形時間構築可能

Lemma [Kasai, Lee+, 2001]

PLCP[i] ≧ PLCP[i-1] - 1

SA PLCP

Φ SA LCP

整数配列1

整数配列2

Page 15: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

PCLP配列のin-place構築

15

Lemma [Kärkkäinen+, 2009]

Φ配列からPLCP配列に線形時間でin-placeに書き換え可能

1. l = 02. For i = 1 to N3. while T[i + l] = T[Φ[i] + l]4. l ← l+15. PLCP[i] = l6. l = max(l-1, 0)

1度しか使われない

Φ[i]を書き換え

Theorem

PLCP配列を線形時間でin-placeに構築可能

Φ整数配列1 PLCP

Page 16: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

新しいデータ構造 : Goto配列

16

✦ Φ配列とは辞書の順序関係をテキスト順に保存した配列✦ SAとは辞書の順序関係を辞書順に保存した配列✦ テキストとはテキストの順序関係をテキスト順に保存した配列✦ Goto配列とはテキストの順序関係を辞書順に保存した配列

テキスト順 辞書順

テキスト順 T Goto

辞書順 Φ SA順序関係

保存位置

新たな配列Goto配列を考え,in-place計算に応用する

Page 17: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

Goto配列

17

i G[i] SA-1[i] SA[i] T[SA[i]..N] 1 2 3 3 aaacatat 2 4 7 4 aacatat 3 7 1 1 acaaacatat4 8 2 5 acatat 5 9 4 9 at 6 10 8 7 atat 7 1 6 2 caaacatat 8 6 10 6 catat 9 3 5 10 t 10 5 9 8 tat

T = acaaacatat

テキストの順序関係を辞書順に保持した配列G[SA-1[i]] = SA-1[i+1] (i > 1), G[SA-1[N]] = SA-1[1]

各suffixの辞書順位をテキスト順に得ることが出来る

`

Page 18: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

Goto配列の応用

18

新手法1 PLCP

PLCP(簡潔)2N + o(N) bits

SA LCP

新手法2 PLCP

PLCP(簡潔)2N + o(N) bits

Goto LCP

Theorem [Manzini 2004]

LCP配列を6~10N bytesで線形時間構築可能

Theorem

LCP配列を5N bytes + 2N bitsで線形時間構築可能

[1] [Sadakane, 2002]

[1]

[1]

Page 19: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

PLCP配列の簡潔表現

19

i 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

PLCP 0 3 2 1 0 0

B 1 0 0 0 0 1 1 1 1 0 1

Kasai, Lee+の定理により対応する1 bitの順序は変わらない

Lemma [Sadakane, 2002]

PLCP[i]をB[1..2N] bitsで表現可能B[j] = 1 iff j = 2(i-1) + PLCP[i] + 1,B[j] = 0 otherwise

PLCP[i] ≧ PLCP[i-1] - 1

Page 20: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

PLCP配列の簡潔表現

20

i 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

PLCP 0 3 2 1 0 0

B 1 0 0 0 0 1 1 1 1 0 1

Lemma [Sadakane, 2002]

PLCP[i]をB[1..2N] bitsで表現可能B[j] = 1 iff j = 2(i-1) + PLCP[i] + 1,B[j] = 0 otherwise

PLCP[i] = select1(B, i) - 2(i-1)-1

o(N) bitsの追加領域でselect操作を行うことにより定数時間でランダムアクセス可能

Page 21: 2013.11.26.Linear time rewriting algorithm.posterTheorem [Nong, 2013] Suffix Arrayをin-placeに線形時間構築可能 SAについてはin-place構築可能であることが知られている

まとめ

21

旧手法 新手法Φ 9N bytes 5N bytes

NSV(PSV) 9N bytes 5N bytes

PLCP 9N bytes 5N bytes

LCP 6~10N bytes 5N bytes + 2N bits

in-place

in-place

in-place

[2] [Crochemore and Ilie, 2008][1] [Kärkkäinen+, 2009]

[3] [Manzini, 2008]

[1]

[1]

[2]

[3]

その他✦ Goto配列の応用例募集中✦ Goto配列の新ネーミング募集中