Java

18. Sorting Algorithms – Bubble Sort, Selection Sort in Java



Java Playlist :

Hey guys, in this lecture we are going to study about Sorting Algorithms (Bubble Sort, Selection Sort)). Sit tight and enjoy the lecture. In case you face any doubt then you can ask your doubt from “Anuj Kumar Sharma Bhaiya” in the comment section or the above Instagram handle. #java. #selectionSorting #javaLanguage

Similar Posts

47 thoughts on “18. Sorting Algorithms – Bubble Sort, Selection Sort in Java
  1. int a[] = {3,1,-2,4,0};

    int n = a.length;

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

    int minIndex = i ;

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

    if(a[j]<minIndex) {

    minIndex = j ;

    }

    }int temp = a[i];

    a[i] = a[minIndex];

    a[minIndex] = temp;

    }for(int item : a) {

    System.out.print(item + " ");

    }

    I did it the same way as he did but the and is coming wrong….pls help

  2. Selection Sort :-
    Minimum Index find karne wala Loop i ke vajah ( i+1) se start karege. Because every first time, the condition will be false.
    So, no need to check it.

  3. This bubble Sort approach is not performance-oriented. Below solution can sort array in the half time (compared to video's solution)

    for (int i = intArray.length – 1; i > 0; i–) {
    for (int j = 1; j <= i; j++) {
    if (intArray[j – 1] > intArray[j]) {
    int temp = intArray[j – 1];
    intArray[j – 1] = intArray[j];
    intArray[j] = temp;
    }
    }
    }

  4. For those who are searching for the Matrix Multiplication question from the previous video, here it is:

    public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    System.out.println("Enter Matrix Dimensions");

    int rows = sc.nextInt();

    int cols = sc.nextInt();

    int a[][] = new int[rows][cols];

    int b[][] = new int[rows][cols];

    int c[][] = new int[rows][cols];

    System.out.println("Enter Matrix 'a'");

    for (int i = 0; i < rows; i++) {

    for (int j = 0; j < cols; j++) {

    a[i][j] = sc.nextInt();

    }

    }

    System.out.println("Enter Matrix 'b'");

    for (int i = 0; i < rows; i++) {

    for (int j = 0; j < cols; j++) {

    b[i][j] = sc.nextInt();

    }

    }

    System.out.println("Result Matrix 'c' is");

    for (int i = 0; i < rows; i++) {

    for (int j = 0; j < cols; j++) {

    for (int k = 0; k < rows; k++) {

    c[i][j] += a[i][k]*b[k][j];

    }

    System.out.print(c[i][j] + " ");

    }System.out.println();

    }

    }

  5. Sir selection Sort me bohot confuse he aapne board pe samjhaya samaj me aagaya but Coding me variable me. Confuse ho gaya iteration kab kese chal raha he i, j, minIndex yeh sab kis tarah se loop me change ho gaya konse loop me swap ho raha he I don't understand it clearly so plzz clear my doutss

  6. Bhaiya Aapne Kaha int minInd = i , lekin 'i' to outer loop ke liye Hain na basically iterations ke liye , to wo Kisi bhi value Jaise ki 5 ke equal kaise ho Sakta hai , inner loop ke liye to "j" hai wo inner loop mein values ko repeat krta hai na.

  7. Bhaiya Aapne Kaha int minInd = i , lekin 'i' to outer loop ke liye Hain na basically iterations ke liye , to wo Kisi bhi value Jaise ki 5 ke equal kaise ho Sakta hai , inner loop ke liye to "j" hai wo inner loop mein values ko repeat krta hai na.

Leave a Reply

Your email address will not be published. Required fields are marked *