Posts

Showing posts with the label Selection Sort

Selection Sort

Time Complexity - O(n^2)  || Space Complexity - O(1) In selection sort, we divide an array into two parts - sorted and unsorted (by i loop here in code) We find the minimum element's index from the unsorted array (here by j loop) and swap public class Main {     public static void main(String[] args) throws Exception {         int[] arr={1,4,4,5,6,2,3,90,120,43,0};                 System.out.println("UnSorted Array :");         for(int i=0;i<arr.length;i++){             System.out.print(arr[i]+" ");         }         System.out.println();         // selection sort         for(int i=0;i<arr.length;i++){                         int minIndex=i;             // find minimum...