VOOZH about

URL: https://www.geeksforgeeks.org/dsa/bitonic-sort/

⇱ Bitonic Sort - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bitonic Sort

Last Updated : 19 Dec, 2025

Bitonic Sort is a parallel sorting algorithm designed to take full advantage of hardware that can perform multiple operations simultaneously.

Unlike traditional sorting algorithms like Quick Sort or Merge Sort, Bitonic Sort is built to exploit parallelism, making it highly effective on GPUs, multi-core processors, and hardware-based sorting networks.

It works only when the number of elements is a power of 2, and it guarantees a fully sorted sequence using a predictable sequence of compare and swap operations.

Understanding Bitonic Sequences

A bitonic sequence is the core concept behind Bitonic Sort.

A sequence is bitonic if it satisfies one of these:

  1. It first increases and then decreases,
  2. Or it can be rotated to form an increasing-then-decreasing sequence.

Examples:

  • [3, 7, 14, 12, 8, 5, 2] → increases then decreases → bitonic
  • [1, 4, 6, 8, 7, 3] → bitonic after rotation

Why bitonic sequences matter:

Bitonic Sort works by recursively building bitonic sequences and then merging them into a fully sorted array. This structure allows the algorithm to perform many compare-and-swap operations simultaneously, which is why it’s ideal for parallel execution.

How Bitonic Sort Works

Phase 1: Build a Bitonic Sequence

  • Divide the array into two halves.
  • Sort the first half ascending and the second half descending.
  • Combine the halves → this forms a bitonic sequence (first increasing, then decreasing).

Example: [3, 7, 4, 8, 6, 2, 1, 5]

  • Left [3, 7, 4, 8] → [3, 4, 7, 8] (ascending)
  • Right [6, 2, 1, 5] → [6, 5, 2, 1] (descending)
  • Combined → [3, 4, 7, 8, 6, 5, 2, 1] (bitonic)

This bitonic sequence allows efficient merging using compare-and-swap operations.

Phase 2: Bitonic Merge

  • Compare elements at a specific distance and swap if out of order.
  • Recursively apply the process to both halves until fully sorted.

Example:

  • [3, 4, 7, 8, 6, 5, 2, 1] → compare distance 4: (3,6), (4,5), (7,2), (8,1) → swap where needed
  • Recursively merge smaller halves: distance 2 → distance 1
  • Result → [1, 2, 3, 4, 5, 6, 7, 8]

The initial ascending/descending halves and fixed compare-swap pattern make this algorithm highly parallelizable.


Output
1 2 3 4 5 6 7 8

Time Complexity:

  • Best Case: O(n log² n)
  • Average Case: O(n log² n)
  • Worst Case: O(n log² n)

Auxiliary Space: O(log n), due to recursion stack space

Stability: No, Bitonic Sort is not stable, since elements may be swapped across sequences during merging.

Understanding Time Complexity for Bitonic Sort

Bitonic Sort first builds bitonic sequences (half ascending, half descending) and then merges them into sorted order.

Each of these two phases has log n levels, and every level performs O(n) comparisons.
Thus, total time = O(n × log n × log n) = O(n log² n).

Although it’s slower than Merge Sort on a single processor, Bitonic Sort is highly effective on parallel hardware, where many compare-swap operations can be executed simultaneously, reducing actual runtime significantly.

Applications of Bitonic Sort

👁 applications_

Advantages and Disadvantages of Bitonic Sort


Comment
Article Tags:
Article Tags: