Bubble Sort

Speed

Number of Elements

[Range: 10-100]

Implementations

          
            void bubbleSort(int array[], int n){
              int temp;

              for (int i = 0; i < n - 1; i++){
                for (j = 0; j < n - i - 1; j++){

                  //If the current value is larger than the next value, swap values
                  if (array[j] > array[j+1]){
                    temp = array[j+1];
                    array[j+1] = array[j];
                    array[j] = temp;
                  }
                }
              }
            }
          
        
          
            def bubbleSort(array):
              n = len(array)

              for i in range(n):
                for j in range(0, n - i - 1):

                #If the current value is larger than the next value, swap values
                if array[j] > array[j+1]:
                  array[j], array[j+1] = array[j+1], array[j]
          
        
          
            function bubbleSort(array){
              var n = array.length;

              for (let i = 0; i < n - 1; i++){
                for (let j = 0; j < n - i - 1; j++){

                  //If the current value is larger than the next value, swap values
                  if (array[j] > array[j+1]){
                    let temp = array[j+1];
                    array[j+1] = array[j];
                    array[j] = temp;
                  }
                }
              }
            }
          
        

About Bubble Sort

Bubble sorts are among one of the simplest sorting algorithms. It is an exponential sort that repeatedly compares the current index with the next index. If the current value is greater than the next value, the sort simply swaps the two values. This process is repeated until the array is sorted.


Time Complexity

The Bubble sorting method has a time complexity of: O(N2)