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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Sho Iizuka
June 19, 2017
Science
9.2k
1
Share
簡潔データ構造輪講資料(順列)
Compact Data Structures: A Practical Approach の Chapter 5: Permutations の輪講資料です。
Sho Iizuka
June 19, 2017
More Decks by Sho Iizuka
See All by Sho Iizuka
半年前の自分に教えたい systemd のハマりどころ
arosh
19
18k
Osaka.Stan#5 LT プログラミングコンテストのデータを分析した話
arosh
1
7.8k
Pythonにおける日本語処理
arosh
1
2.2k
FM-index による全文検索
arosh
0
53
円と円の外接線の求め方
arosh
0
81
円と円の交点の求め方
arosh
0
47
Other Decks in Science
See All in Science
Bear-safety-running
akirun_run
0
140
Physical AIを支えるWeights & Biases
olachinkei
1
340
力学系から見た現代的な機械学習
hanbao
4
4.2k
共生概念の整理と AIアライメントの構想
hiroakihamada
0
200
データベース04: SQL (1/3) 単純質問 & 集約演算
trycycle
PRO
0
1.4k
水耕栽培:古代の知恵から宇宙農業まで
grow_design_lab
0
120
フィードフォワードニューラルネットワークを用いた記号入出力制御系に対する制御器設計 / Controller Design for Augmented Systems with Symbolic Inputs and Outputs Using Feedforward Neural Network
konakalab
0
140
My Little Monster
juzishuu
0
700
機械学習 - pandas入門
trycycle
PRO
0
590
Van Dare naar Durf
voginip
0
200
KISHIMOTO Atsuo
genomethica
0
140
良書紹介04_生命科学の実験デザイン
bunnchinn3
0
160
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
840
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.6k
Producing Creativity
orderedlist
PRO
348
40k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
150
エンジニアに許された特別な時間の終わり
watany
107
240k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
420
Ethics towards AI in product and experience design
skipperchong
2
290
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
850
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
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