a priority queue for small integers. 1st step: prove this priority queue capacity: n (w / logn...
TRANSCRIPT
A priority queue for small integers
1st Step: Prove this
Priority queuecapacity: n (w / logn loglogn)-bit keys
insert, find-min, delete-min: constant timespace: O(n)
Preliminary lemmas(1)
31 75
42 8621 43 65 87
O(log k)1 word
1 word2 words
wordsn/k
wordsn/k
109
1211 13
21 43 65 87
O(n/k. log k)31 75
42 86109 1211 13
O(log k)
wordsn/k 2
wordsn/k
Preliminary lemmas(2)
Priority queuecapacity: O(k) (w / k)-bit keys
insert, find-min, delete-min: constant timedelete: constant amortized time
B1
B2
Amortized bounds:Structure
buffers
keysk 2of lists sorted
2or 0,1, contains Bi
i
R
M
3.4 priority queuecapacity: k keys
3.4 priority queue
iBeach of and
R of minimum Collects
B0
Blog(n/k)
.
.
.
Amortized bounds:Notes
from cameit Bor Rh about whic
n informatiokey each with associate We
keyper time)n log1O( )k2logk2O(
logk)O(2in merged becan Bin lists full 2
n loglogn log k Let
i
ii
ii
B1
B2
Amortized bounds:insert (w/o delete-min)
R
M
B0
Blog(n/k)
.
.
.
3
1
75
42 86
find-min, delete-min
O(1) per key
O(1 / logn) per key
1
delete, (insert)
O(1) per key
insert
O(1)
1 2 83 4 5 6 7
B1
B2
Amortized bounds:insert (w/ delete-min)
R
M
B0
Blog(n/k)
.
.
.
98 1110
21 43 65 307
1312 1514
98
21 43 65 7
30
10
1
8
8 131211109 1514
9 10 11 12 13 301514
10
R’’’
R’’ B1
B2
Worst-case insertions:Structure
R’
3.4 priority queuecapacity: k keys
B0
Blog(n/k)
.
.
.
A sorted listContains k keys
in 1 word
M
Worst-case insertions:Notes
imeconstant t geach takin steps, n logk2
into divided asit view we time,)n logk2O(
logk)O(2 takesBin lists full 2 Merging
round a insertionsk
imeconstant tin
deletions general supports M that Pretend
i
i
ii
R’’ B1
B2
Worst-case insertions:Part 1
R’
B0
Blog(n/k)
.
.
.
R’’’
M
37
51
37
51
86
42
86
42
find-min, delete-min
O(1)
R’’ B1
B2
Worst-case insertions(2)Part 2
R’
B0
Blog(n/k)
.
.
.M
R’’’ 7531
20 21 22 23 27262524
8642k / logn
steps
.
.
.
No overloading: w/o delete-min
i
ii
Bin stepsn logk spend weroundevery
lists, themerge tosteps n logk2 takesB
merged are lists 2 thebefore
rounds 2 kesfurther tait and ,B toB from
moved islist second a before rounds 2least At i
1-ii
i
7531
No overloading:w/ delete-min
• delete-min– If minimum key μ in R’, R’’ → delete-min– If μ in R’’’ → delete the first– If μ in Bi →
min-pointer
min-pointer
1
8642
M12
68666462
67656361...
...
Bi
Deletions from M
M M’
8642
7531
11
18161412
17151311
68666462
67656361
1
12
2
......
Bi
Bj
delete-min, insert
O(1)
Total cost = O(log n)
.
.
.
Priority queues for arbitrary integers
Next Step
DONE!
Q Priority queuefind-min: constant time
insert, delete-min: O(loglog n) time
Q
15
8
2 54
1 19
3 23
2 8
151
54
23
Insert
54
19
∞1
Q
15
8
1
3
2
23
Delete-min
54
19
1
19
2
Pseudo Code
Recursive
Analysis
• 2w-bit keys– Recursive log(2 logn loglogn) = O(loglogn) tim
es to reduce to (w / logn loglogn)-bit keys– Total time = O(loglogn)