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
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
[SF Ruby Conf 2025] Rails X
palkan
3
1.5k
Evolving SEO for Evolving Search Engines
ryanjones
0
360
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
360
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
560
Being A Developer After 40
akosma
PRO
92
590k
RailsConf 2023
tenderlove
30
1.6k
The SEO Collaboration Effect
kristinabergwall1
1
620
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
590
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
The agentic SEO stack - context over prompts
schlessera
0
1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
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アルゴリズムと同じ