September 2019
Intermediate to advanced
816 pages
18h 47m
English
Bubble sort is a simple algorithm that basically bubbles up the elements of the array. This means that it traverses the array multiple times and swaps the adjacent elements if they are in the wrong order, as in the following diagram:

The time complexity cases are as follows: best case O(n), average case O(n2), and worst case O(n2)
The space complexity case is as follows: worst case O(1)
A utility method implementing the Bubble sort is as follows:
public static void bubbleSort(int[] arr) { int n = arr.length; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (arr[j] > arr[j + 1]) { int temp = arr[j]; arr[j] ...