Priority Queues and Sorting for Read-Only Data Tetsuo Asano 1 , Amr - - PowerPoint PPT Presentation

priority queues and sorting for read only data
SMART_READER_LITE
LIVE PREVIEW

Priority Queues and Sorting for Read-Only Data Tetsuo Asano 1 , Amr - - PowerPoint PPT Presentation

Priority Queues and Sorting for Read-Only Data Tetsuo Asano 1 , Amr Elmasry 2 , and Jyrki Katajainen 3 , 4 1 Japan Advanced Institute for Science and Technology 2 Alexandria University 3 University of Copenhagen 4 Jyrki Katajainen and Company c


slide-1
SLIDE 1

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (1)

Priority Queues and Sorting for Read-Only Data

Tetsuo Asano1, Amr Elmasry2, and Jyrki Katajainen3,4

1 Japan Advanced Institute for Science and Technology 2 Alexandria University 3 University of Copenhagen 4 Jyrki Katajainen and Company

slide-2
SLIDE 2

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (2)

Model of computation

random access, read only sequential access, write only random access, modifiable

x0 x1 xN−1

input data: workspace:

  • utput stream:

word RAM N elements S bits Related model: space-bounded Turing machine Motivation: special devices where working space is limited (mobile devices) and where writing is expensive (flash memories)

slide-3
SLIDE 3

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (3)

Online exercise: Selection sort

  • 1. How would you modify selection sort so that it is suit-

able for the space-bounded random-access machine?

  • 2. What is the space-time trade-off of this algorithm?
  • 3. Can you improve the space-time trade-off?
slide-4
SLIDE 4

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (4)

Problem: A priority queue for read-only data

O(S + w) bits (w word size, lg N ≤ S ≤ N/ lg N)

x1 xN−1

input data: workspace: N elements Q

x0

Operations for a priority queue Q Q.minimum(): Return the position of the minimum element in Q. Q.insert(p): Insert the element at position p of the read-only array into Q. Q.extract(p): Extract the element at position p of the read-

  • nly array from Q.
slide-5
SLIDE 5

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (5)

Market analysis

Data structure Space

minimum insert extract

queue of pennants Θ(N lg N) O(1) O(1) O(lg N) navigation pile Θ(N) O(1) O(lg N) O(lg N) adjustable binary heap Θ(S) O(1) O(N lg N/S + lg S) O(N lg N/S + lg S) common precursor Θ(S) O(N/S2 + lg S)O(N/S + lg S) amort. O(N/S + lg2 S) adjustable navigation pile Θ(S) O(1) O(1) O(N/S + lg S)

Beame 1991: The space-time product of any sorting al- gorithm is Ω(N2). Pagter & Rauhe 1998: An optimal sorting algorithm is

  • btained by combining an adjustable binary heap and

their adjustable priority queue. this paper: Simplification of the latter result; heapsort with an adjustable navigation pile gives the optimal sorting bound.

slide-6
SLIDE 6

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (6)

Application: Priority-queue sort

procedure: priority-queue-sort input: A: read-only array of N elements; S: space target

  • utput: stream of elements produced by the print statements

1 P ← navigation-pile(A, S) 2 for x ∈ {0, 1, . . . , N − 1} 3

P.insert(x)

4 repeat N times 5

y ← P.minimum()

6

P.extract(y)

7

print(A[y])

Workspace: O(S + w) bits (w word size in bits) Worst-case running time: O(N2/S + N lg S) (lg N ≤ S ≤ N/ lg N)

slide-7
SLIDE 7

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (7)

Assumptions

  • 1. N is known beforehand.
  • 2. The elements are extracted from the data structure in

monotonic fashion.

  • 3. The elements are inserted into the data structure se-

quentially in streaming-like fashion starting from the first element stored in the read-only input. O(S + w) bits (w word size, lg N ≤ S ≤ N/ lg N)

x1 xN−1

input data: workspace: N elements Q

x0

slide-8
SLIDE 8

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (8)

Memory-adjustable tournament tree

3 1 1 2 3 1 2 3 4 5 6 7 4 7 9 8 5 2 6 latest output: 1 at position 4007 S = 8; ⌈N/S⌉ elements per bucket

in the covered range – pointer to the minimum – nodes stored in breadth-first order

slide-9
SLIDE 9

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (9)

Memory-adjustable navigation pile

latest output: 1 at position 4007 1 1 2 3 011|011 11|01 11|11 1|1 1|0 1|0 0|0 2 bits 4 bits 6 bits 9 5 2 6 4 7 3 8 S = 8; ⌈N/S⌉ elements per bucket

– which quantile h bits – which bucket h bits – height h – nodes stored in breadth-first order –

lg ¯ S

  • h=1

¯ S · min {2h, ⌈lg N⌉} 2h < 4¯ S bits (¯ S = 2⌈lg S⌉)

slide-10
SLIDE 10

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (10)

minimum

  • The last bucket in use is an

insertion buffer.

  • The second last bucket is a

submersion buffer (if any).

  • Maintain pointers to the min-

ima of the buffers and the pile, and information where the overall minimum is. Worst-case running time: O(1)

latest output: 1 at position 4007 1 1 2 3 011|011 11|01 11|11 1|1 1|0 1|0 0|0 2 bits 4 bits 6 bits 9 5 2 6 4 7 3 8 S = 8; ⌈N/S⌉ elements per bucket

slide-11
SLIDE 11

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (11)

insert

  • Insert

into the insertion buffer; perform part of the incremental submersion; up- date the minimum pointers if necessary.

  • If the insertion buffer is full,

make this buffer a submer- sion buffer. Worst-case running time: O(1)

latest output: 1 at position 4007 1 1 2 3 011|011 11|01 11|11 1|1 1|0 1|0 0|0 2 bits 4 bits 6 bits 9 5 2 6 4 7 3 8 S = 8; ⌈N/S⌉ elements per bucket

slide-12
SLIDE 12

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (12)

extract

  • Locate the correct bucket.
  • Insertion buffer: Update the

minimum pointers.

  • Submersion buffer: Redo the

whole submersion and update the minimum pointers.

  • Pile:

Find the minimum of the bucket; update the mini- mum pointers.

  • Update the navigation infor-

mation on the path above.

  • Scan

the elements in the quantiles of the siblings of the nodes along the path.

  • The work done when scan-

ning the quantiles

  • f

the siblings is proportional to

lg ¯

S h=1

  • N/(¯

S · 2h)

  • ≈ N/¯

S. Worst-case running time: O(N/S + lg S)

latest output: 1 at position 4007 1 1 2 3 011|011 11|01 11|11 1|1 1|0 1|0 0|0 2 bits 4 bits 6 bits 9 5 2 6 4 7 3 8 S = 8; ⌈N/S⌉ elements per bucket

slide-13
SLIDE 13

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (13)

Open: Find the kth smallest of N elements

Inventors Workspace in bits Running time Munro and Raman 1996 Θ(lg N) O(N1+ε) Raman and Ramnath 1999 Θ(lg2 N) O(N lg2 N) Frederickson 1987 Θ(lg3 N) O(N lg N/ lg lg N) Blum et al. 1973 Θ(N lg N) Θ(N) COCOON 2013 O(N) Θ(N)

  • What is the correct worst-case space-time trade-off?
  • In the randomized case, the bound Θ(N lg logS N) is

tight for all S ≫ lg N.

slide-14
SLIDE 14

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (14)

Open: Compute the convex hull of N points

  • Is the space-time trade-off the same for this problem

as for sorting?

slide-15
SLIDE 15

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (15)

Summary: The key techniques used

  • 1. Node numbering with implicit links between nodes

(as in a binary heap),

  • 2. buffering,
  • 3. incremental construction,
  • 4. bit packing and unpacking, and
  • 5. quantile thinning.
slide-16
SLIDE 16

c

Performance Engineering Laboratory

TAMC 2013 in Hong Kong on 20 May, 2013 (16)

Further direction

Siu Wing Cheng: Does the model and the algorithm ex- tend naturally to the external-memory case? I.e. cal- culate the number of I/Os and keep the input on a read-only media. My answer: The model extends naturally and may even be more relevant than the model considered by us. How- ever, the data structure does not extend optimally since the quantiles are scattered over the read-only input.