Bubble Sort

What is Bubble Sort?

Bubble sort is a sorting algorithm, which arranges elements present in a list in certain order such as ascending(increasing) or descending(decreasing).

Steps

  1. Starting with the first element(index = 0), compare the current element with the next element of the array.

  2. If the current element is greater than the next element of the array, swap them.

  3. If the current element is less than the next element, move to the next element. Repeat Step 1.

Java Implementation of Bubble sort

Characteristics of Bubble sort

  • Time Complexities

    • Worst Case: O(n*n)

  • Space Complexities

    • Worst Case: O(1)

  • In place: Yes

  • Stable: Yes