Worst-Case Ef fi cient External-Memory Priority Queues Gerth - - PowerPoint PPT Presentation
Worst-Case Ef fi cient External-Memory Priority Queues Gerth - - PowerPoint PPT Presentation
Worst-Case Ef fi cient External-Memory Priority Queues Gerth Stlting Brodal MaxPlanckInstitut f ur Informatik Saarbr ucken Germany Jyrki Katajainen Datalogisk Institut Kbenhavns Universitet Denmark July 1998 Worst-Case Ef
Worst-Case Efficient External-Memory Priority Queues
Priority Queues
Maintain a set of
N elements from a totally ordered universe underINSERT
x – Insert element x into the setDELETEMIN
– Delete and return the minimum of the setINSERT and DELETEMIN can be implemented with
log- N
- comparisons
– Williams, 1964
- G. S. Brodal, J. Katajainen
2
Worst-Case Efficient External-Memory Priority Queues
External Memory Model
– Aggarwal, Vitter, 1988
A A A- CPU
registers
- Internal memory
External memory External memory
- Y I/O
Complexity measures Internal : # comparisons External : # I/Os Assumptions
M- B ,
- log
- G. S. Brodal, J. Katajainen
3
Worst-Case Efficient External-Memory Priority Queues
External-Memory Merge Sorting
Theorem
N elements stored in O- N
- blocks can be sorted with
- N
- N
- I/Os.
Algorithm: (1) Sort in internal memory all runs of
M elements(2) In
log M B N M iterations apply a- M
- ary merging algorithm
to obtain lists of length
M- M
- i.
The sorting algorithm is optimal w.r.t. both comparisons and I/Os. – Aggarwal, Vitter, 1988
- G. S. Brodal, J. Katajainen
4
Worst-Case Efficient External-Memory Priority Queues
Worst-Case Effeciency
Internal Each priority queue operation should require
log- N
- comparisons in the worst-case
External The I/Os should be divided evenly among the operations, i.e., one I/O for every
- B
- log
- th operation.
- G. S. Brodal, J. Katajainen
5
Worst-Case Efficient External-Memory Priority Queues
External-Memory Priority Queues
Binary heap – Williams, 1964 – Random memory accesses imply one I/O every
O CPU operation.Fishspear – Fischer, Patterson, 1994 –
O- N
- N
- I/Os for N operations. Uses
Heap + B elements/node – Wegner, Teuhola, 1989 –
O- log
- N
- I/Os for every
- O
Buffer tree * – Arge, 1995 –
O- N
- I/Os for N operations.
Heap with buffers * – Fadel et al., 1997 – Similar bounds as for buffer trees. * No worst-case guarantee on the individual operations
- G. S. Brodal, J. Katajainen
6
Worst-Case Efficient External-Memory Priority Queues
New Result
Theorem DELETEMIN and INSERT can be done with
log N- comparisons and one I/O for every
- log
Outline of the Data Structure
Internal part External part
- MIN
- NEW
- Work area
- Q
Sorted lists of length
- M
- M
- i
MIN stores the overall
O M smallest elements fast DELETEMIN.NEW stores the most recently inserted
O M elements fast INSERT.[ small elements are inserted directly into MIN ] The external part stores exactly
B elements per block[ all elemenst are larger than the elements in MIN ]
- G. S. Brodal, J. Katajainen
7
Operations
K- M
- INSERT
– If
x- max MIN then swap
– Insert
x into NEW– If
jNEWj- K then perform BATCHINSERT
with
K elements from NEW.DELETEMIN
- – If MIN
- then perfrom BATCHDELETE
Merge the result with NEW Move the
K smallest elements to MIN– Delete and return
min MINBATCHINSERT – Create a new list of length
K and assign it rank 1–
i- – while #list of rank
- M
Merge the lists with rank
iAssign the resulting list rank
i- i
- i
- BATCHDELETE
– Fetch the
K smallest elements from externalmemory to internal memory rank
L- blog
- lists
- M
- G. S. Brodal, J. Katajainen
8
Worst-Case Efficient External-Memory Priority Queues
Amortized Result
Lemma The described data structure supports INSERT and DELETEMIN with amortized
log N comparisons and- B
- I/Os.
[ Identical bounds follow by using buffer trees and external heaps ]
Worst-Case Bounds?
Incremental list merging– Thorup, 1996
Incremental batch operations Start BATCHDELETE before MIN gets empty.- G. S. Brodal, J. Katajainen
9
Incremental List Merging
Lists of rank
i L- i
- i
- L
- L
- i
- i
- L
- MERGESTEP
– Perform
K steps of the list merging at rank i.– If the merging is finished, then make the resulting list
- L
- (list promotion)
BATCHINSERT – Create a new list with rank one –
i MERGESTEP i- G. S. Brodal, J. Katajainen
10
Deletions
BATCHDELETE deletes and returns the
K leastelements of the lists.
- The length of the lists decreases.
- The maximum rank increases.
Possible solution: Incremental global rebuilding. Our solution: 1) If the incremental merging of rank
i finishes,but
j- L
- K
- M
- i, then we do not promote
- L
to rank
i- .
2) Let
R be the maximum rank of a list.If the resulting list
- L
- K
- M
- R
then
- L
- .
3) If
K elements are deleted from- L
MERGESTEP
i.4) Always perform MERGESTEP
R afterBATCHDELETE
- R
- O
- log
- G. S. Brodal, J. Katajainen
11
Worst-Case Efficient External-Memory Priority Queues
Conclusion
The first worst case external-memory priority-queue implementation.Open Problems
Is the definition of “worst-case” reasonable in practice ? Experimental studies. Can buffer trees be deamortized, i.e., how can buffer trees support- perations with worst-case
- log
- I/Os for
- G. S. Brodal, J. Katajainen
12