Docsity

Improve Run Generation - Advanced Data Structures - Lecture Slides, Slides of Computer Science

Toggle sidebar
bg1
Improve Run Generation
•Overlap input,output, and internal CPU work.
•Reduce the number of runs (equivalently, increase
average run length).
DISK
MEMORY
DISK
Internal Quick Sort
62 8 5 11 10 4 1 9 7 3
Use 6 as the pivot (median of 3).
Input first, middle, and last blocks first.
In-place partitioning.
Input blocks from the ends toward the middle.
Sort left and right groups recursively.
Can begin output as soon as left most block is ready.
4 2 3 5 1 6 10 11 9 7 8
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Improve Run Generation - Advanced Data Structures - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Improve Run Generation

  • • Overlap input,output, and internal CPU work.Reduce the number of runs (equivalently, increase

average run length).

DISK

MEMORY

DISK

Internal Quick Sort

Use 6 as the pivot (median of 3).

Input first, middle, and last blocks first.

In-place partitioning.

Input blocks from the ends toward the middle.

Sort left and right groups recursively.

Can begin output as soon as left most block is ready.

Alternative Internal Sort Scheme

DISK

DISK

B1 B2 B

Partition into 3 areas, each maybe more than 1 block in size.

Steady State Operation

Read fromdisk Write todisk Rungeneration

• Synchronization is done when the current input area getsfull (the current output area will be empty at this time).

O0 O

I0 I

Initialize

Initialize

O0 O

I0 I

Initialize

O0 O

I0 I

Initialize

O0 O

I0 I

Generate Run 1

O0 O

I0 I

(^35) 4

Generate Run 1

O0 O

I0 I

(^35) 4

1

O

Generate Run 1

O

I0 I

(^35) 4

1

O

Generate Run 1

O

I0 I

(^35) 4

1

O

O

I0 I

1

(^19) 2

Continue With Run 1

O

O

I0 I

1

(^19) 2

Continue With Run 1

O

O

I0 I

1

(^19) 2

Continue With Run 1

O

O

I0 I

(^61) 3

O

O

I0 I

(^61) 3

Continue With Run 1

• Lettree. k be number of external nodes in loser

• Run size >= k.

• Sorted input => 1 run.

• Reverse of sorted input => n/k runs.

• Average run size is ~2k.

  • Memory capacity = m records.
  • Run size using fill memory, sort, and outputrun scheme = m.
  • Use loser tree scheme. ƒ Assume block size is b records. ƒ Need memory for 4 buffers (4b records). ƒ Loser tree k = m – 4b. ƒ Average run size = 2k = 2(m – 4b). ƒ 2k >= m when m >= 8b.
  • Assume b = 100.

m 600 1000 5000 10000 k 200 600 4600 9600 2k 400 1200 9200 19200