The document describes the bubble sort algorithm sorting an array of numbers from highest to lowest over 57 steps. It starts with the array [7, 3, 6, 5, 1, 9, 2, 4, 8] and with each pass of the algorithm, the largest remaining number bubbles to the end of the array, until the array is fully sorted from lowest to highest.
40. 40
Algorithms in Java
Bubble sort:
3 1 5 2 4 6 7 8 9
Once again the last number has been put in the correct
location: next cycles will skip 7, 8 and 9
52. 52
Algorithms in Java
Bubble sort:
1 [2] [3] 4 5 6 7 8 9
At this stage the array is ordered. However as the algorithm is
not aware of this, the remaining cycles will run anyway
57. 57
Algorithms in Java
Bubble sort:
1) Bigger arrays take longer than smaller ones as this
algorithm runs in O(N2
), as N = number of elements of the
array
2) Extremely disordered arrays take longer than fairly ordered
ones as less swaps are necessary