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
8.4k
簡潔データ構造輪講資料(順列)
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
19
17k
Osaka.Stan#5 LT プログラミングコンテストのデータを分析した話
arosh
1
7.1k
Pythonにおける日本語処理
arosh
1
2.1k
FM-index による全文検索
arosh
0
36
円と円の外接線の求め方
arosh
0
70
円と円の交点の求め方
arosh
0
42
Other Decks in Science
See All in Science
コンピュータビジョンによるロボットの視覚と判断:宇宙空間での適応と課題
hf149
1
380
データベース02: データベースの概念
trycycle
PRO
2
920
Hakonwa-Quaternion
hiranabe
1
140
知能とはなにかーヒトとAIのあいだー
tagtag
0
100
防災デジタル分野での官民共創の取り組み (1)防災DX官民共創をどう進めるか
ditccsugii
0
310
風の力で振れ幅が大きくなる振り子!? 〜タコマナローズ橋はなぜ落ちたのか〜
syotasasaki593876
1
110
NASの容量不足のお悩み解決!災害対策も兼ねた「Wasabi Cloud NAS」はここがスゴイ
climbteam
1
170
データマイニング - コミュニティ発見
trycycle
PRO
0
160
システム数理と応用分野の未来を切り拓くロードマップ・エンターテインメント(スポーツ)への応用 / Applied mathematics for sports entertainment
konakalab
1
410
データベース06: SQL (3/3) 副問い合わせ
trycycle
PRO
1
640
高校生就活へのDA導入の提案
shunyanoda
0
6k
Collective Predictive Coding as a Unified Theory for the Socio-Cognitive Human Minds
tanichu
0
100
Featured
See All Featured
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.7k
Gamification - CAS2011
davidbonilla
81
5.5k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3k
How to train your dragon (web standard)
notwaldorf
97
6.3k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
10
600
Being A Developer After 40
akosma
91
590k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
190
55k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.4k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
115
20k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.7k
Large-scale JavaScript Application Architecture
addyosmani
514
110k
Raft: Consensus for Rubyists
vanstee
140
7.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