Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

BITONIC SORT

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).

* However, Bitonic sort must be done if the number of


elements to sort are , or else, the procedure will be
fail.
 Bitonic sort is only suitable for implementation in
hardware and parallel processor array,but it is
impractical for real-life use in traditional software
context.To understand how bitonic sort work, we
assume that each processor has only 1 number,
and the number of processors is
 The sequence of processors becomes to a
sequence of numbers
For example: 3, 5, 2, 7, 6, 1, 4, 8 is a sequence of
processors/numbers

III. Bitonic sequence

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

 An increasing sequence is considered Bitonic


with the decreasing part is empty. Similarly, a
decreasing sequence is also Bitonic with the
increasing part is empty.
IV. Bitonic sort

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

 After this phase, we have a 8-element Bitonic


sequence with 2 parts: (3,4,7,8) and (6,5,2,1).
The first is increasing and the second is
decreasing
- Now, we have a 8-element Bitonic sequence with
an increasing part and a decrease part
- How can transform this Bitonic sequence to an
increasing sequence?
 Bitonic Merge

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

parallel steps to obtain the final sorted list in a


parallel implementation, which corresponds to a
time complexity of in parallel
implementation.
- For example, the sequence of size 8 needs log(8) =
3 phases. Phase 1 has 1 step, phase 2 has 2 steps,
phase 3 has 3 steps

Time complexity summary


- Each step makes n/2 comparisions. Therefore, total
comparisions
- Thus, in serial implementation, it takes time
complexity, which is slower than Merge Sort and
Quick Sort
- However, in parallel implementation, where
multiprocessor could work parallel, the complexity
is only (very fast !!!)

How the algorithm works:


* The following is a bitonic sorting network with 16 inputs:
* Alternative representation
Each green box, in the diagram above, performs the same
operation as a blue box, but with the sort in the opposite
direction.
So, each green box could be replaced by a blue box
followed by a crossover where all the wires move to the
opposite position. This would allow all the arrows to point
the same direction, but would prevent the horizontal lines
from being straight.
However, a similar crossover could be placed to the right
of the bottom half of the outputs from any red block, and
the sort would still work correctly, because the reverse of a
bitonic sequence is still bitonic. If a red box then has a
crossover before and after it, it can be rearranged
internally so the two crossovers cancel, so the wires
become straight again.
Therefore, the following diagram is equivalent to the one
above, where each green box has become a blue plus a
crossover, and each orange box is a red box that
absorbed two such crossovers:
The arrowheads are not drawn, because every
comparator sorts in the same direction. The blue and red
blocks perform the same operations as before. The
orange blocks are equivalent to red blocks where the
sequence order is reversed for the bottom half of its inputs
and the bottom half of its outputs. This is the most
common representation of a bitonic sorting network

Source:https://www.geeksforgeeks.org/bitonic-sort/
https://en.wikipedia.org/wiki/Bitonic_sorter
and the other relevant documents.

You might also like