Title: Eliminating Amortizations PurelyFunctionalDataStrctures ?? ?6?
1Eliminating Amortizations PurelyFunctionalDataSt
rctures ?? ?6?
2??????? (1)
- Imperative Queue (Ch2)
- ??????????????????snoc????
- Persistent ???
- head, tail, snoc ???????? O(1)
1
2
3
4
3??????? (2)
- Functional Queue (Ch5)
- Front??Rear??2????????
- Front 0 ????? Rear ? reverse
- Persistent ???
- ????????reverse??????? O(n)
- ??????? (persistency????????????) O(1)
1
2
3
5
4
4??????? (3)
- Functional Queue via Lazy Evaluation (Ch6)
- Front??Rear??2????????
- Front1 Rear ??????? reverse
- Persistent ???
- ????????reverse??????? O(n)
- ??????? (persistency???????????) O(1)
1
2
3
5
4
5????
- Functional Real-Time Queue (Ch7)
- Persistent ???
- ????????O(1)
- ?????????? O(1)
?
6Real-Time Queues ?????
- 6??????????Queue??
- ???? ?suspension???????????
- reverse ? suspension ????????????
- ??? ?????? ??suspension?force????????????
reverse???Rear??? - ???suspension?force???????????????????????????????
?? - revese?Front Rear ??????????Front ? tail
????force????????1??tail?1???????
7Real-Time Queues ?????
- Real-Time Queue ??
- ???? ?suspension???????????
- ? tail ??????????????????
- ????tail?????reverse?suspension?????(??????)?????
?
8Real-Time Queues
- OCaml ?????????
- MyRTQ.ml
- ????
- ?Front1 Rear ?????reverse???????
- ???suspension??????force???
9Amortization?? 6??Queue???
- Rear?????
- f _at_ rev r
- rev ? incremental ???(force?????????????)?????????
????????????? - rotate f r
- incremental???????????
- Schedule, exec
- ???????????????????????????????????????????
10Amortization?? ???????? (1)
- Monolithic ? suspension ??????incremental
????????? - ? suspension ???????????????????????????
- ? _at_rev ? rotate, ?????O(1)
?????(internal cost) suspension
????????????????????? suspension
??????????O(1)????????????????????????? (?suspend?
??????????????????)
11Amortization?? ???????? (2)
- ?suspension??????????????suspension???????suspensi
on??????????????? - ? schedule??
12Exercise
- 7.1
- 6?? _at_rev ? rotate ???????(Scheduling???????)?snoc,
head, tail ????????O(n) ?? O(log n) ????????? - Ans
- Schedule???????rotate??????force?
- ??suspension???????????snoc????????????????O(log
n)
13Exercise
- 7.2
- Real-time Queue ??????????????f r
????????r ? s ????????????????????????? - Ans.
- s ???rotate????? tail?? snoc??
- r snoc??
- ???? ???rotate????? - tail?? snoc??
s 2 r - fr gt rs ???????????
- ?????????
14??????2
- Binomial Heaps (Ch3)
- insert, deleteMin, findMin, merge ?? O(log n)
- Binomial Heaps (Ch5)
- Physicists Method ?? persistency????????????
insert ?? O(1) ???? - Lazy Binomial Heaps (Ch6)
- ???????????????persistency ???????insert ??
O(1) ???? - Amortization??? (Ch7)
- insert ? ?? O(1) ????
15Binomial Heaps ????
- ?????2???????????????
- ??? 2a12a2...2an ?Heap?? ???2a1??????2a2????
???2an?????????
16Binomial Heaps ????
type tree T of int Elt.t tree list type
heap tree list
insert e h insTree (T(0,e,)) h insTree t h
match h with -gt t hdtl -gt if
rank t lt rank hd then th else
insTree (link t hd) tl
17??????
- ??????????suspension? ?monolithic?? incremental
?????? - ????????????????????
- monolithic ? insTree ? incremental, O(1) ?
- Scheduling
insert e h insTree (T(0,e,)) h insTree t h
match h with -gt t hdtl -gt if
rank t lt rank hd then th else
insTree (link t hd) tl
181 Incremental ?
type tree T of Elt.t tree list type bit
Zero One of tree type heap bit list
,
,
,
0
0
191 Incremental ?
insTree t h match h with -gt
One t Zerotl -gt (One t) tl (One
hd)tl -gt Zero insTree
(link t hd) tl
201 Incremental ?
insTree t h match force h with SNil -gt
lazy (SCons(One t, lazy(SNil))) SCons(Zero,
tl) -gt lazy (SCons(One t, tl)) SCons(One
hd, tl) -gt lazy (SCons(Zero, insTree (link t
hd) tl))
212 Scheduling
- ?insTree???suspension?????????????????suspension?
????????????????
insTree t h match force h with SNil -gt
lazy (SCons(One t, lazy(SNil))) SCons(Zero,
tl) -gt lazy (SCons(One t, tl)) SCons(One
hd, tl) -gt lazy (SCons(Zero, insTree (link t
hd) tl))
222 Scheduling
0
0
0
1
- ????suspension
- ????????
- ???????
- ??? bit ?0????????????????????? bit ??????
1
1
0
0
1
0
1
0
1
0
1
1
1
1
1
0
1
0
1
0
0
1
0
1
0
1
1
0
1
1
1
1
1
0
1
1
0
1
1
1
1
1
1
1
1
232 Scheduling
0
0
0
1
type schd bit stream list type heap bit
stream schd let exec (bsbsl) match force
bs with SCons(Zero, t) -gt tbsl
SCons(One _,_) -gt bsl let insert x (bs,sc)
let bs insTree ... bs in (bs, exec (exec
(bssc)))
1
1
0
0
1
0
1
0
1
0
1
1
1
1
1
0
1
0
1
0
0
1
0
1
0
1
1
0
1
1
1
1
1
0
1
1
0
1
1
1
1
1
1
1
1
242 Scheduling
- Q ??2?exec????
- A 6?????????? Amortized Cost?2??????
252 Scheduling (Thm7.1)
Schedule
- 1??insert???2?exec????????????
- Schedule?????range???????
- ???????range??????????Zero?1????
- ??????range??????????Zero?2????
0
0
0
0
0
0
0
1
0
0
1
0
0
0
0
1
0
0
0
0
1
0
0
1
0
0
0
1
1
0
0
1
0
0
0
1
1
0
0
1
???Heap
262 Scheduling (Thm7.1) ??
- ??????
- ???? (empty) ??????? ? ??
- ????????? insert ?1????????????
- insert ??????Zero?One????
- ????(4??)
27??????4??
1 ??????B
1 ??????A
0
0
1
0
0
1
insert
1
1
1
0
0
1
insert
0
1
1
0
0
1
exec 2
1
1
1
0
0
1
exec 2
0,1 ??????
0
1
1
0
0
1
insert
0
0
0
0
1
1
insert
1
0
1
0
0
1
exec 2
0
0
0
0
1
1
exec 2
1
0
1
0
0
1
0,...,0,1 ??????
28??????
- deleteMin, findMin, merge
- O(log n) ????????????? schedule
?????????????????????? - insert ?????????? schedule ????? O(log n) ????
- MyBinHeap2.ml
29???
- Lazy Amortized Persistent ???????Lazy
WorstCase Persistent ?????? - ????????? incremental ???
- ?????? suspension ? Schedule ?????
- ????????????????????????Schedule ???