Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
JOIss2015
Search
sappleki
August 16, 2015
260
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JOIss2015
ソースコードは
https://gist.github.com/71acf65ba6609cf54f00.gitとか
sappleki
August 16, 2015
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
What the history of the web can teach us about the future of AI
inesmontani
PRO
2
740
Practical Orchestrator
shlominoach
192
12k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
540
Prompt Engineering for Job Search
mfonobong
0
520
Evolving SEO for Evolving Search Engines
ryanjones
0
330
The untapped power of vector embeddings
frankvandijk
2
1.9k
[SF Ruby Conf 2025] Rails X
palkan
3
1.5k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
410
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
530
The Curious Case for Waylosing
cassininazir
1
570
Transcript
1 橋本早記 すべての共通接頭辞
2 • 2つのリストxsとysの最長共通接頭辞(length of the longest common prefix)の長さを llcp xs
ys とする • ex) llcp “click” “clock” = 2
3 xs a b a c a b a c
a b allcp xs 10 0 1 0 6 0 1 0 2 0 llcp “abacabacab” “abacabacab” = 10 llcp “abacabacab” “bacabacab” = 0 llcp “abacabacab” “acabacab” = 1 …...
4 • すべての共通接頭辞(all the common prefixes) の長さを表す関数allcpを考える
5 • allcp xs = map (llcp xs) (tail xs)
と定義される * tail xs --- xsの空でない末尾部分 xs tail xs
6 • allcp xs の定義を直接実行するとo(n^2) 線形時間にしたい
7 • us,vs,wsを任意の3つの文字列を用意する • llcp us vs = m llcp
vs ws = n とする • llcp us ws = min n m m/=n m + llcp (drop m us)(drop m ws) m==n * drop(k ks)-- ksのk番目までの要素を除く drop (k ks) k
8 • m<nの場合 us[m+1] != vs[m+1] vs[m+1] == ws[m+1] llcp
us ws = m • m>nの場合 us[n+1] == vs [n+1] vs[n+1] != ws[n+1] llcp us ws =n
9 • m==nの場合 drop m us , drop m vs で照合を続ける
m n ? ?us[m+1] とvs[m+1]が同じかどうかわからない
10 • 1<=i , j < n (n==length xs)として •
p = llcp xs (drop i xs) q = llcp xs (drop j xs)とおくと xs a b a c a b a c a b allcp xs 10 0 1 0 6 0 1 0 2 0 * xs[j]==q xs[i]==p xs[2]==1 xs[4]==6
11 • drop i xsはpまでの接頭辞が一致 →j<iよりjまでの接頭辞も一致 • 残りの一致部分はxsからj文字除いた文字列 drop j
xs とdrop j (drop i xs)のllcpとなる • p = j + llcp (drop j xs) (drop (i+j) xs)となる
12 • k=i+j として us = xs , vs=drop j xs
, ws =drop k xs とおく
13 • llcp xs (drop k xs)= 1. min (p-j)
q q != p-j 2. q + llcp (drop q xs) (drop (q+k) xs) q == p-j
14 1. allcp xsのk番目の要素は allcp xs [i]とallcp xs[j]だけによって決定する 2. j==p
(1<i<k && j=k-i<p)でない場合 愚直に調べる k==0,1の場合は直接計算
15 • k<i+p j=k-iとしてllcp xs (drop j xs)と llcp (drop
j xs) (drop k xs)のminを求める llcp xs (drop j xs)==llcp (drop j xs) (drop k xs)なら また愚直に求める i j p k i+p p
16 • k>=i+p 前に保存されていないので llcp xs(drop k xs)を愚直に計算する j i
p k i+p p
17 • 愚直に計算する 1回調べる度に不一致は1回 m回一致するとi+pは少なくともmずつ増える i+p<=nより一致する回数は全体で高々n回
18
19 • snoc , !! ,drop はO(n)で定数時間演算ではない データの精緻化
20 • drop Haskell配列ライブラリのData.Array を使ってllcpを書き換える • snoc HaskellのData.Sequenceライブラリを使う リストO(n)を配列に
21 • !! Data.Sequenceライブラリを使っても インデックス演算は対数時間になる
22 queueを使う *insert 新しい要素をqueueの最後に追加 *remove 先頭を取り出して残りを返す *empty-空のqueueを返す *elems-queueの要素を返す
23 実行結果
24
25 • Boyer-Mooreアルゴリズムなどの文字列照合の ための前処理であるZアルゴリズムと同じ