Eliminating Amortizations PurelyFunctionalDataStrctures ?? ?6? - PowerPoint PPT Presentation

About This Presentation
Title:

Eliminating Amortizations PurelyFunctionalDataStrctures ?? ?6?

Description:

Eliminating Amortizations PurelyFunctionalDataStrctures 6 2006/06/23 – PowerPoint PPT presentation

Number of Views:91
Avg rating:3.0/5.0
Slides: 30
Provided by: kmonosNet
Category:

less

Transcript and Presenter's Notes

Title: Eliminating Amortizations PurelyFunctionalDataStrctures ?? ?6?


1
Eliminating Amortizations PurelyFunctionalDataSt
rctures ?? ?6?
  • 2006/06/23
  • ???

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)

?
6
Real-Time Queues ?????
  • 6??????????Queue??
  • ???? ?suspension???????????
  • reverse ? suspension ????????????
  • ??? ?????? ??suspension?force????????????
    reverse???Rear???
  • ???suspension?force???????????????????????????????
    ??
  • revese?Front Rear ??????????Front ? tail
    ????force????????1??tail?1???????

7
Real-Time Queues ?????
  • Real-Time Queue ??
  • ???? ?suspension???????????
  • ? tail ??????????????????
  • ????tail?????reverse?suspension?????(??????)?????
    ?

8
Real-Time Queues
  • OCaml ?????????
  • MyRTQ.ml
  • ????
  • ?Front1 Rear ?????reverse???????
  • ???suspension??????force???

9
Amortization?? 6??Queue???
  • Rear?????
  • f _at_ rev r
  • rev ? incremental ???(force?????????????)?????????
    ?????????????
  • rotate f r
  • incremental???????????
  • Schedule, exec
  • ???????????????????????????????????????????

10
Amortization?? ???????? (1)
  • Monolithic ? suspension ??????incremental
    ?????????
  • ? suspension ???????????????????????????
  • ? _at_rev ? rotate, ?????O(1)

?????(internal cost) suspension
????????????????????? suspension
??????????O(1)????????????????????????? (?suspend?
??????????????????)
11
Amortization?? ???????? (2)
  • ?suspension??????????????suspension???????suspensi
    on???????????????
  • ? schedule??

12
Exercise
  • 7.1
  • 6?? _at_rev ? rotate ???????(Scheduling???????)?snoc,
    head, tail ????????O(n) ?? O(log n) ?????????
  • Ans
  • Schedule???????rotate??????force?
  • ??suspension???????????snoc????????????????O(log
    n)

13
Exercise
  • 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) ????

15
Binomial Heaps ????
  • ?????2???????????????
  • ??? 2a12a2...2an ?Heap?? ???2a1??????2a2????
    ???2an?????????

16
Binomial 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
18
1 Incremental ?
  • ???2????????

type tree T of Elt.t tree list type bit
Zero One of tree type heap bit list


,
,
,
0
0
19
1 Incremental ?
  • ???2????????

insTree t h match h with -gt
One t Zerotl -gt (One t) tl (One
hd)tl -gt Zero insTree
(link t hd) tl
20
1 Incremental ?
  • ???2????????
  • Lazy?

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))
21
2 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))
22
2 Scheduling
  • insert ??????(????????)

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
23
2 Scheduling
  • insert ??????(????????)

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
24
2 Scheduling
  • Q ??2?exec????
  • A 6?????????? Amortized Cost?2??????

25
2 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
26
2 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 ???
Write a Comment
User Comments (0)
About PowerShow.com