The following
pseudocode describes the sorting process. In the code, a is the array to be sorted, low is the index of the first item in the sub-array to be sorted, k and count is the number items in the sub-array that are being sorted in this function call. direction is a
boolean value that determines whether the sub-array is being sorted into ascending / descending order. The function call bitonicSort(a, 0, n, 1) is used to sort a (ascending), where n is the number of items in a .
function bitonicMerge(
a,
low,
count,
direction)
is if count > 1
THEN k ←
count / 2 // Compare and swap elements across the halves
for i ←
low to low + k
do // determine if two elements of
a are out of order in relation to the direction of sorting.
if (
direction == 1
AND a[i] >
a[i + k])
OR (
direction == 0
AND a[i] 1
THEN k ←
count / 2 // Sort first/second half into ascending/descending order
bitonicSort(
a,
low, k, 1)
bitonicSort(
a,
low + k, k, 0) // Merge entire sequence in desired order
bitonicMerge(
a,
low,
count,
direction) == Complexity ==