Review of the
Two Pass Multiway Sort Algorithm
- Pass 1
Review of the
Two Pass Multiway Sort Algorithm
- Pass 2
Merge sort upto
M−1 chunks of
sorted fragments using
1 output buffer:
Maximum file size imposed by
Pass 2 of the TPMMS algorithm
Maximum file size imposed by
Pass 2 of the TPMMS algorithm
Important observation about
Pass 2 of the
TPMMS algorithm
Pass 2
limits
the number of chunks:
Because we
need to use
1 buffer to
scan (read)
1 (sorted) chunk
Important observation about
Pass 2 of the
TPMMS algorithm
Pass 2
does not limits
the size of the chunks:
Because we
scan (read) the
(sorted) chunks
one block at a time !
How to increase the
size of the sorted chunks ?
Step 1:
use M buffers to
sort the
input file into
chunks of M blocks:
Write the
sorted chunks
(each chunk is M blocks)
to disk !
How to increase the
size of the sorted chunks ?
Step 2a:
use M− buffers to
merge sort the
first (M−1) chunks into a
chunk of M(M−1) blocks:
Write the
sorted chunk
(the chunk is M(M−1) blocks)
to disk !
How to increase the
size of the sorted chunks ?
Step 2b:
use M− buffers to
merge sort the
next (M−1) chunks into a
chunk of M(M−1) blocks:
Write the
sorted chunk
(the chunk is M(M−1) blocks)
to disk !
-- And so on !!!
The 3-pass Multiway Sort Algorithm
- Pass 1
# Disk IO of
Pass 1:
2 B(R)
The 3-pass Multiway Sort Algorithm
- Pass 2
# Disk IO of
Pass 2:
2 B(R)
The 3-pass Multiway Sort Algorithm
- Pass 2
# Disk IO of
Pass 3:
1 B(R)
(don't count the last write - default is pipelining)
Maximum file size that can be sorted by the
3-pass multiway sort algorithm
Number of IOs used by the
3-pass multiway sort algorithm
Final comment....
Final comment:
algorithm can be
generalized to
4-pass, 5-pass, ..., n-pass
Example:
the 4-pass multiway sort algorithm
Pass 1:
sort input into
chunks of
M blocks
Final comment....
Final comment:
algorithm can be
generalized to
4-pass, 5-pass, ..., n-pass
Example:
the 4-pass multiway sort algorithm
Pass 2:
merge sort groups of
(M−1) different chunks into a
single chunk of
(M−1)M blocks:
Final comment....
Final comment:
algorithm can be
generalized to
4-pass, 5-pass, ..., n-pass
Example:
the 4-pass multiway sort algorithm
Pass 3:
merge sort groups of
(M−1) different chunks into a
single chunk of
(M−1)2M blocks:
Final comment....
Final comment:
algorithm can be
generalized to
4-pass, 5-pass, ..., n-pass
Example:
the 4-pass multiway sort algorithm
Pass 4:
merge upto
(M−1) different chunks
Performance and Buffer requirement of the 4-pass multiway sort
algorithm
❮
❯