Professional Documents
Culture Documents
Sorting Algorithms
Comparison based
compare-exchange
O(n log n)
Noncomparison based
Uses known properties of the elements
O(n) - bucket sort etc.
Comparisons
How compare elements on different nodes
Compare-Exchange
Compare-Split
Sorting Networks
max{x,y}
min{x,y}
x
y
min{x,y}
max{x,y}
Sorting Network
Merge Sort
Simplest parallel sorting algorithm?
Steps
Problem
How to merge the lists
Bitonic Sort
Key operation:
rearrange a bitonic sequence to ordered
Bitonic Sequence
sequence of elements <a0, a1, , an-1>
There exists i such that <a0, ,ai> is
monotonically increasing and <ai+1, , an-1> is
monotonically decreasing or
There exists a cyclic shift of indicies such that the
above is satisfied.
Bitonic Sequences
<1, 2, 4, 7, 6, 0>
First it increases then decreases
i=3
<8, 9, 2, 1, 0, 4>
Consider a cyclic shift
i will equal 3
Bitonic Sort
Procedure BitonicSort
for i = 0 to d -1
for j = i downto 0
if (i + 1)st bit of iproc <> jth bit of iproc
comp_exchange_max(j, item)
else
comp_exchange_min(j, item)
endif
endfor
endfor
comp_exchange_max and comp_exchange_min compare and
exchange the item with the neighbor on the jth dimension