Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
簡潔データ構造輪講資料(順列)
Search
Sho Iizuka
June 19, 2017
Science
1
6.7k
簡潔データ構造輪講資料(順列)
Compact Data Structures: A Practical Approach の Chapter 5: Permutations の輪講資料です。
Sho Iizuka
June 19, 2017
Tweet
Share
More Decks by Sho Iizuka
See All by Sho Iizuka
半年前の自分に教えたい systemd のハマりどころ
arosh
18
14k
Osaka.Stan#5 LT プログラミングコンテストのデータを分析した話
arosh
1
5.6k
Pythonにおける日本語処理
arosh
1
1.9k
FM-index による全文検索
arosh
0
17
円と円の外接線の求め方
arosh
0
19
円と円の交点の求め方
arosh
0
34
Other Decks in Science
See All in Science
Microbiology Labs.
maleehafatima
0
120
AI Alignment: A Comprehensive Survey
s_ota
0
180
汎用原子シミュレータMatlantis のご紹介
matlantis
0
120
AI科学の何が“哲学”の問題になるのか ~問いマッピングの試み~
rmaruy
1
900
名古屋市立大学データサイエンス学部 秋のオープンキャンパス模擬授業20231111
trycycle
1
1.1k
O ChatGPT e outras IAs vão mudar toda a pesquisa científica
cardososampaio
0
170
iRIC v4 Solvers
nkmr_rl
0
3k
救急外来でのめまい診療_中枢性めまいを見逃さない!
psasa
0
140
FIBA W杯の日本代表って組み合わせ次第で2次ラウンド行けたんじゃね?をデータで検証
saltcooky12
0
200
Direct Preference Optimization
zchenry
0
120
HAS Dark Site Orientation
astronomyhouston
0
4.9k
How we developed a data exchange format: Lessons learned from Camtrap DP
peterdesmet
1
140
Featured
See All Featured
Producing Creativity
orderedlist
PRO
336
39k
Fireside Chat
paigeccino
20
2.6k
Fantastic passwords and where to find them - at NoRuKo
philnash
36
2.5k
Side Projects
sachag
451
41k
How GitHub Uses GitHub to Build GitHub
holman
468
290k
Why You Should Never Use an ORM
jnunemaker
PRO
50
8.6k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
A Modern Web Designer's Workflow
chriscoyier
688
190k
Six Lessons from altMBA
skipperchong
20
3k
Designing for Performance
lara
601
67k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
Faster Mobile Websites
deanohume
297
30k
Transcript
Chapter 5: Permutations Compact Data Structures: A Practical Approach (Gonzalo
Navarro) 発表者:飯塚 1
発表の流れ 2 1. 順列 [1, ] の最悪エントロピーの評価 ➡ 順列の保存は log
bits でほとんど最適 2. Inverse *+() を実現する簡潔順列 ➡ 1 + log + () bits の空間計算量で 1/ の時間計算量を実現 ( > 0) 3. Power 5() を実現する簡潔順列 ➡ 任意の について *+() と同様の時間・空間計算量 内部的には *+() の簡潔順列を利⽤して実現される
順列 [1, ] の最悪エントロピーの評価 3 • 順列 [1, ]:1, 2,
…, n を並べ替えた配列 • ⼤きさ の順列は ! 種あるので ℋ9: = log = log ! a. ≥ 1 のとき ! ≤ ? より ℋ9: ≤ log ? = log b. log ! = log ∏ ? 5A+ = ∑ log ? 5A+ Jensen の不等式 ∑ 5 ? 5A+ ≤ + ? ∑ 5 ? 5A+ が使える E log ? 5A+ ≤ log 1 E ? 5A+ = log 1 ⋅ 1 2 + 1 = (log + 1 − 1) = log + 1 − Θ() c. Stirling の近似を使うと log ! = log − Θ() 各要素 log bits の配列 (Section 3.1) に保存するだけで ほとんど最適 ➡ 有⽤な機能という付加価値を付ける
実現したい有⽤な機能 4 • *+ : = となる を⾒つける • 5():
… … のように を 回適⽤したとき の遷移先を求める • 1 + log + () bits のスペースで 1/ の時間計算量を実現 ( > 0) • log + log ではないから succinct ではない? ➡ = 1/ log とすれば log + bits のスペースで log の時間計算量
5.1 Inverse Permutations 5 【⽬的】*+ : = となる を⾒つける a.
あらかじめ *+ を持っておくと時間計算量 1 ➡ 補助領域が log bits … log が達成できない b. + = () ,O = + , … を繰り返して = となる を⾒つけたらストップ ➡ 時間計算量が () … は⼤きい b. をベースに⾼速化するためのアイデア 1. cycle decomposition 2. shortcut
cycle decomposition 6 1 2 3 4 5 6 7
8 9 10 11 12 () 10 7 3 5 8 1 11 12 4 6 9 2 5 8 12 2 7 9 4 11 10 6 1 3
shortcut 7 5 8 12 2 7 9 4 11
Inverse *+ の計算 1. 基本的には順列の⽅向に進む 2. 逆向きのショートカットがあったら1度だけ使う 3. = となる を⾒つけたらストップ 時間計算量 : パラメータ 以上の間隔が空かないように 逆向きのショートカットを⽤意
shortcut の格納 8 5 8 12 2 7 9 4
11 1 2 3 4 5 6 7 8 9 10 11 12 () 10 7 3 5 8 1 11 12 4 6 9 2 0 1 0 0 0 0 0 1 1 0 0 0 8 9 2 :ショートカットの有無 :ショートカット先 は左詰めにして の rank で アクセスする
空間計算量と時間計算量 9 • , 元の順列: log bits • , shortcut
の有無: n bits の bit vector。constant time の rank が必要。4.2.2 の⽅法で + bits • , shortcut 先:サイクルの⻑さを としたとき 個々のサイクルは / 個のショートカットを持つから の要素数は O? WX+ を超えない(←サイクル⻑が + 1 の場合) よって O WX+ log bits • = O WX+ とおくと 1 + log + + () bits • = 1/ log とすれば log + bits のスペースで = 1/ = log の時間計算量
5.2 Powers of Permutations 10 サイクル順に要素を並べた配列を作ると Power は簡単に計算できる + …
[5, 8, 12, 2, 7, 11, 9, 4] O … [10, 6, 1] Z … [3] 5 8 12 2 7 9 4 11 10 6 1 3
Power の計算例 11 • + … [5, 8, 12, 2,
7, 11, 9, 4] • O … [10, 6, 1] • Z … [3] O[(12) を計算したい 1. 12 は + の 3 番⽬の要素である 2. + 3 − 1 + 20 mod + + 1 = + 22 mod 8 + 1 = 9 *+(10) を計算したい 1. 10 は O の 1 番⽬の要素である 2. O 1 − 1 − 1 mod O + 1 = O −1 mod 3 + 1 = 1 *+ のデータ構造は不要だった? ➡ 5 の実装に必要
格納⽅法 (1) 12 + … [5, 8, 12, 2, 7,
11, 9, 4] O … [10, 6, 1] Z … [3] • :+ , O , … を並べた配列。 log bits • :+ , O , … の終端の位置が 1 になる bit vector。 pred と succ (Section 4.5.2) を使ってサイクル⻑を 求める ※ 元の順列 の格納はもはや不要 1 2 3 4 5 6 7 8 9 10 11 12 5 8 12 2 7 11 9 4 10 6 1 3 0 0 0 0 0 0 0 1 0 0 1 1
格納⽅法 (2) 13 • これだけでは「 上での の出現位置」を答えるのに かかってしまう • そこでポインタ
を⽤意して 1 で計算可能にする 5 8 12 2 7 11 9 4 10 6 1 3 0 0 0 0 0 0 0 1 0 0 1 1 1 2 3 4 5 6 7 8 9 10 11 12
格納⽅法 (3) 14 • に ⌈log ⌉ bits, に ⌈log
⌉ bits, に + () 必要 • これでは 2 log + () bits 必要で簡潔にならない • 実は は不要 5 8 12 2 7 11 9 4 10 6 1 3 0 0 0 0 0 0 0 1 0 0 1 1 1 2 3 4 5 6 7 8 9 10 11 12
格納⽅法 (4) 15 • に Section 5.1 の⼿法を適⽤して *+ を計算可能にする
• の 番⽬の要素は *+() で計算可能 • よって に 1 + log + + () bits, に + () bits • = 1/ log のとき全体で log + bits 5 8 12 2 7 11 9 4 10 6 1 3 0 0 0 0 0 0 0 1 0 0 1 1 1 2 3 4 5 6 7 8 9 10 11 12
計算例 16 O[(12) を計算したい 1. 12の 上での位置は 12 = 3
2. , 3 = 0, , 3 = 8 よりサイクル⻑は 8 3. 3 − 1 + 20 mod 8 + 1 = 7, *+ 7 = 9 5 8 12 2 7 11 9 4 10 6 1 3 0 0 0 0 0 0 0 1 0 0 1 1 1 2 3 4 5 6 7 8 9 10 11 12