Selection Sort

Speed

Number of Elements

[Range: 10-100]

Implementations

          
            void selectionSort(int array[], int n){
              int j;
              int min;
              int temp;

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

                for (j = i + 1; j < n; j++){
                  if (array[j] < array[min]){
                    min = j;
                  }
                }

                if (min != i){
                  temp = array[i];
                  array[i] = array[min];
                  array[min] = temp;
                }
              }
            }
          
        
          
            def selectionSort(array):
              for i in range(len(array)):
                min = i

                for j in range(i + 1, len(array)):
                  if array[min] > array[j]:
                    min = j

                array[i], array[min] = array[min], array[i]
              
          
        
          
            function selectionSort(array){
              var n = array.length;
              var min;

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

                for (let j = i + 1; j < n; j++){
                  if (array[j] < array[min]){
                    min = j;
                  }
                }
                let temp = array[i];
                array[i] = array[min];
                array[min] = temp;
              }
              
            }
          
        

About Selection Sort

The Selection sorting method repeatedly looks for the smallest value in the input array and inserts it into the nth position in the array (starting from the first index).


Time Complexity

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