Professional Documents
Culture Documents
Bitonic Sort (Quang)
Bitonic Sort (Quang)
I. Sorting algorithm
- Sorting algorithm is an algorithm to arrange an
unordered collection of items into a meaningful
order
- Sorting can be grouped into two types:
1. Comparision Based: making a number of
comparision to find the smaller or bigger
element. Example: Bubble Sort, Selection sort
2. Non-comparision based. Example: Bucket sort,
Count sort,…
II. Bitonic sort introduction
- Bitonic sort is a parallel sorting algorithm
- Average time complexity is in parallel
implementation (very fast!!)
* Why Bitonic sort?
- Although the number of comparisions done by
Bitonic sort is more than Merge sort, Bitonic sort is
better for parallel implementation
- Bitonic sort compares elements in predefined
elements anf the sequence of comparisions does
not depend on data (features of Sorting network).
A sequence of n
numbers is said to be bitonic if
and only if
1. for some
k,
2. for some k,
3. a can be split into two parts that can be
interchanged to give either of the first two
cases
Characteristic
The charactersitic of Bitonic sequence is that if we
compare-and-swap between the element and
for all i, in a sequence of size n, we obtain
two bitonic sequence of size such that all element
in the left sequence is smaller than elements in the
right sequence.
Bitonic Merge
- Bitonic merge is a process to combine an
increasing list and a decreasing to only increasing
(or decreasing) one.
- Hence, if we apply recursively these compare-and-
swap operations to a given bitonic sequece, we will
get a sorted sequence
- For example, if we have 2 Bitonic sequence of size
4, the left is in increasing order and the right in
decreasing:
Step by step demo
- First, we start by forming 4-element bitonic
sequence from consecutive 2-element sequence
- Assuming we have x0, x1 and x2, x3 are the two
pairs. We sort x0,x1 in increasing order and x2,x3
in decreasing order
An 4-element Bitonic sequence with 2-element
increase and 2-element decrease
- Then, we combine these 2 sequences to a 8-
element Bitonic sequence:
o Transform the first sequence to an increasing
sequence
o Transform the second seuqence to a
decreasing sequence
Bitonic sort
The Bitonic sort can be split into k phases (with
)
Phase 1: convert adjacent pair of values into
increasing/decreasing sequences, i.e., into 4-
element bitonic sequence
Phase 2 to k-1: sort each m-element bitonic
sequence into increasing/decreasing
sequences and merge each pair of adjacent
sequences into a 2m-element bitonic
sequence, until reaching the last 2 n/2-element
sequences.
Phase k: Merge the 2 n/2-element sequence
into a n-element bitonic sequence. After this
phase, the final sequence will be in sorted
order.
Complexity
- Bitonic sort is an in-place algorithm => Space
complexity is: O(1).
- Given an unsorted list of size , there are k
phases, with each phase i taking i parallel steps.
Therefore, total it takes
Source:https://www.geeksforgeeks.org/bitonic-sort/
https://en.wikipedia.org/wiki/Bitonic_sorter
and the other relevant documents.