Bubblesort
NOTE: Your Device may work slower on a large Dataset!
-
-
Complexity Analysis
Time Complexity: O(n2)
Space Complexity: O(1)
How it works
Bubblesort is a simple sorting algorithm that repeatedly steps through the input list element by element, comparing the current element with the one after it, comparing their values if needed. These passes through the list are repeated until no swaps have to be performed during a pass, meaning that the list has become fully sorted. The algorithm, which is a comparison sort, is named for the way the larger elements "bubble" up to the top of the list.
Pseudocode Implementation
// Initialize n as Length of Array BubbleSort(A as Array, n as int){ for i = 0 to n-
2 { for j = 0 to n-2 { if Array[j] > Array[j+1] { swap(Array[j], Array[j+1]) } } } }
Source: https://fullyunderstood.com/pseudocodes/bubble-sort/