bi tonic sort with examples
TRANSCRIPT
-
7/23/2019 Bi Tonic Sort with examples
1/23
CS 584
-
7/23/2019 Bi Tonic Sort with examples
2/23
Sorting
One of the most common operationsOne of the most common operations
Definition:Definition:
Arrange an unordered collection ofArrange an unordered collection of
elements into a monotonically increasing orelements into a monotonically increasing or
decreasing order.decreasing order.
Two categories of sortingTwo categories of sorting internal (fits in memory)internal (fits in memory)
external (uses auxiliary storage)external (uses auxiliary storage)
-
7/23/2019 Bi Tonic Sort with examples
3/23
Sorting Algorithms
Comparison asedComparison ased
compare!exchangecompare!exchange
O(n log n)O(n log n)
"oncomparison ased"oncomparison ased
#ses $nown properties of the elements#ses $nown properties of the elements
O(n)O(n)! uc$et sort etc.! uc$et sort etc.
-
7/23/2019 Bi Tonic Sort with examples
4/23
Parallel Sorting Issues
%nput and Output se&uence storage%nput and Output se&uence storage
'here'here
ocal to one processor or distriutedocal to one processor or distriuted
ComparisonsComparisons
*ow compare elements on different nodes*ow compare elements on different nodes
+ of elements per processor+ of elements per processor One (compare!exchange !!, comm.)One (compare!exchange !!, comm.)
-ultiple (compare!split !!, comm.)-ultiple (compare!split !!, comm.)
-
7/23/2019 Bi Tonic Sort with examples
5/23
Compare-Exchange
-
7/23/2019 Bi Tonic Sort with examples
6/23
Compare-Split
-
7/23/2019 Bi Tonic Sort with examples
7/23
Sorting Networks
peciali/ed hardware for sortingpeciali/ed hardware for sorting
ased on comparatorased on comparator
x
y
xy
maxx!y"
minx!y"
minx!y"maxx!y"
-
7/23/2019 Bi Tonic Sort with examples
8/23
Sorting Network
-
7/23/2019 Bi Tonic Sort with examples
9/23
Parallel Sorting Algorithms
-erge ort-erge ort
0uic$ ort0uic$ ort
1itonic ort1itonic ort
Others 2Others 2
-
7/23/2019 Bi Tonic Sort with examples
10/23
#erge Sort
implest parallel sorting algorithmimplest parallel sorting algorithm
tepsteps
Distriute the elementsDistriute the elements
34eryody sort their own se&uence34eryody sort their own se&uence
-erge the lists-erge the lists
5rolem5rolem
*ow to merge the lists*ow to merge the lists
-
7/23/2019 Bi Tonic Sort with examples
11/23
$itonic Sort
6ey operation:6ey operation:
rearrange a itonic se&uence to orderedrearrange a itonic se&uence to ordered
1itonic e&uence1itonic e&uence
se&uence of elements 7ase&uence of elements 7a889 a9 a9 2 9 a9 2 9 an!n!,,
There exists i such that 7aThere exists i such that 7a889 2 9a9 2 9a ii, is, is
monotonically increasing and 7amonotonically increasing and 7a i;i;92 9 a92 9 an!n!, is, ismonotonically decreasing ormonotonically decreasing or
There exists a cyclic shift of indicies such that theThere exists a cyclic shift of indicies such that the
ao4e is satisfied.ao4e is satisfied.
-
7/23/2019 Bi Tonic Sort with examples
12/23
$itonic Se%uences
79 9 ?9 8,79 9 ?9 8,
@irst it increases then decreases@irst it increases then decreases
i Bi B
79 9
-
7/23/2019 Bi Tonic Sort with examples
13/23
&earranging a $itonic Se%uence
et s 7aet s 7a889 a9 a9 2 9 a9 2 9 an!n!,,
aanE
all elements after all elements after iiare from decreasingare from decreasing
e&uence se&uence s
-
7/23/2019 Bi Tonic Sort with examples
14/23
&earranging a $itonic Se%uence
34ery element of s34ery element of s::is smaller thanis smaller than
e4ery element of se4ery element of s
-
7/23/2019 Bi Tonic Sort with examples
15/23
&earranging a $itonic Se%uence
-
7/23/2019 Bi Tonic Sort with examples
16/23
$itonic #erging Network
-
7/23/2019 Bi Tonic Sort with examples
17/23
'hat a(out unor)ere) lists*
To use the itonic merge for n items9 we mustTo use the itonic merge for n items9 we must
first ha4e a itonic se&uence of n items.first ha4e a itonic se&uence of n items.
Two elements form a itonic se&uenceTwo elements form a itonic se&uence Any unsorted se&uence is a concatenation ofAny unsorted se&uence is a concatenation of
itonic se&uences of si/e
-
7/23/2019 Bi Tonic Sort with examples
18/23
#apping onto a hypercu(e
One element per processorOne element per processor
tart with the sorting networ$ mapstart with the sorting networ$ maps
3ach wire represents a processor3ach wire represents a processor
-ap processors to wires to minimi/e-ap processors to wires to minimi/e
the distance tra4eled during exchangethe distance tra4eled during exchange
-
7/23/2019 Bi Tonic Sort with examples
19/23
$itonic #erging Network
-
7/23/2019 Bi Tonic Sort with examples
20/23
$itonic #erge on +ypercu(e
-
7/23/2019 Bi Tonic Sort with examples
21/23
$itonic SortProce)ure $itonicSort
,or i . to ) -/
,or 0 i )ownto .
i, 1i 2 /3st(it o, iproc 0th(it o, iproc
comp6exchange6max10! item3
else
comp6exchange6min10! item3
en)i,
en),oren),or
comp6exchange6max an) comp6exchange6min compare an)
exchange the item with the neigh(or on the 0th)imension
-
7/23/2019 Bi Tonic Sort with examples
22/23
$itonic Sort Stages
-
7/23/2019 Bi Tonic Sort with examples
23/23
Assignment
5ic$ ? random integers5ic$ ? random integers
Draw the 1itonic ort networ$Draw the 1itonic ort networ$
tep through the 1itonic sort networ$ totep through the 1itonic sort networ$ to
produce a sorted list of integers.produce a sorted list of integers.
3xplain how the if statement in the3xplain how the if statement in the
1itonic sort algorithm wor$s.1itonic sort algorithm wor$s.