Worst-Case Ef fi cient External-Memory Priority Queues Gerth - - PowerPoint PPT Presentation

worst case ef fi cient external memory priority queues
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Worst-Case Efficient External-Memory Priority Queues

Gerth Stølting Brodal

Max–Planck–Institut f¨ ur Informatik Saarbr¨ ucken Germany

Jyrki Katajainen

Datalogisk Institut Københavns Universitet Denmark July 1998

slide-2
SLIDE 2

Worst-Case Efficient External-Memory Priority Queues

Priority Queues

Maintain a set of

N elements from a totally ordered universe under

INSERT

x – Insert element x into the set

DELETEMIN

– Delete and return the minimum of the set

INSERT and DELETEMIN can be implemented with

log
  • N
  • comparisons

– Williams, 1964

  • G. S. Brodal, J. Katajainen

2

slide-3
SLIDE 3

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
M = Size of the internal memory B = I/O block size N = # elements in the priority queue

Complexity measures Internal : # comparisons External : # I/Os Assumptions

M
  • B ,
B
  • log
M B N M
  • G. S. Brodal, J. Katajainen

3

slide-4
SLIDE 4

Worst-Case Efficient External-Memory Priority Queues

External-Memory Merge Sorting

Theorem

N elements stored in O
  • N
B
  • blocks can be sorted with
N log
  • N
comparisons and
  • N
B log M B N B
  • I/Os.

Algorithm: (1) Sort in internal memory all runs of

M elements

(2) In

log M B N M iterations apply a
  • M
B
  • ary merging algorithm

to obtain lists of length

M
  • M
B
  • i.

The sorting algorithm is optimal w.r.t. both comparisons and I/Os. – Aggarwal, Vitter, 1988

  • G. S. Brodal, J. Katajainen

4

slide-5
SLIDE 5

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
M B N B
  • th operation.
  • G. S. Brodal, J. Katajainen

5

slide-6
SLIDE 6

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
B log
  • N
  • I/Os for N operations. Uses
O push down stacks.

Heap + B elements/node – Wegner, Teuhola, 1989 –

O
  • log
  • N
B
  • I/Os for every
Bth operation. Optimal for M
  • O
B .

Buffer tree * – Arge, 1995 –

O
  • N
B log M B N M
  • 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

slide-7
SLIDE 7

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
B
  • log
M B N B th operation.

Outline of the Data Structure

Internal part External part

  • MIN
  • NEW
  • Work area
  • Q
Q k

Sorted lists of length

  • M
  • M
B
  • 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

slide-8
SLIDE 8

Operations

K
  • M
  • INSERT
x

– If

x
  • max MIN then swap
x and max MIN

– 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 MIN

BATCHINSERT – Create a new list of length

K and assign it rank 1

i
  • – while #list of rank
i
  • M
B do

Merge the lists with rank

i

Assign the resulting list rank

i
  • i
  • i
  • BATCHDELETE

– Fetch the

K smallest elements from external

memory to internal memory rank

L
  • blog
M B jLj B c
  • lists
  • M
B log M B N M
  • G. S. Brodal, J. Katajainen

8

slide-9
SLIDE 9

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
log M B N 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

slide-10
SLIDE 10

Incremental List Merging

Lists of rank

i L
  • i
L
  • i
  • L
n i i L i z
  • L
  • i
L
  • i
  • L
n i i
  • MERGESTEP
i

– Perform

K steps of the list merging at rank i.

– If the merging is finished, then make the resulting list

  • L
i a list of rank i
  • (list promotion)

BATCHINSERT – Create a new list with rank one –

i MERGESTEP i
  • G. S. Brodal, J. Katajainen

10

slide-11
SLIDE 11

Deletions

BATCHDELETE deletes and returns the

K least

elements 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
i j
  • K
  • M
B
  • i, then we do not promote
  • L
i

to rank

i
  • .

2) Let

R be the maximum rank of a list.

If the resulting list

  • L
R
  • K
  • M
B
  • R
,

then

  • L
R gets rank R
  • .

3) If

K elements are deleted from
  • L
i, we perform

MERGESTEP

i.

4) Always perform MERGESTEP

R after

BATCHDELETE

  • R
  • O
  • log
M B N M
  • G. S. Brodal, J. Katajainen

11

slide-12
SLIDE 12

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
O
  • log
M B N B
  • I/Os for
B operations ?
  • G. S. Brodal, J. Katajainen

12