Java Algorithm - Bubble Sort

preview_player
Показать описание

Java Algorithm - Bubble Sort - In this Algorithm tutorial, I show how a bubble sort algorithm works. You can code this in most any language. I just used java, so if you want to use C++, just make sure the syntax is c++ specific. The semantics will be the same. This algorithm runs O(n^2) so it is not efficient on bigger inputs, but it is a good intro to sorting type of algorithm.
Рекомендации по теме
Комментарии
Автор

This is the most understandable explanation of how the bubble sort works :D
Thanks! Cheers!

yaroslavnochnyk
Автор

are there any videos that go through it step by step using spring tools suite

ashade
Автор

This is realy the best explanation of bubblesort Please, do more about algorithms in Java! Big thanks for your job! It is realy helpful!!!

WarnerBosss
Автор

hmm can you explain the -i a little more. So both i and j are .length -1 and both are incrementing, but what does the -i do?

JoshTlife
Автор

Very good explanation. What will happen when we get rid of the outer loop. Can't the program run just fine as well?

Playncooler
Автор

easy explanation thank u. Can u pls do the rest of sorting algorithms

sidramowlana
Автор

im having a problem with the curly braces, dunno if im missing one or where

trevorbekun
Автор

Very good explanation, and video. Please do more, I am extremely interested in algorithms!

TheGandalf
Автор

For some reason my number are slightly mixed up

ashade
Автор

everything stays exactly the same if you remove -i in j loop

deniso
Автор

Everything is perfect, but you're not returning the method to some array variable. You're just calling the method like we call the method of type 'void'.

talhatariq
Автор

private static int[] bubbleSort(int[] A){
boolean swapped = true;
for(int i = A.length - 1; swapped && i > 0; i--){
swapped = false;
for(int j = 0; j < i; j++){
if(A[j] > A[j + 1]){
int temp = A[j + 1];
A[j + 1] = A[j];
A[j] = temp;
swapped = true;
}
}
}
return A;

this will make the best case of bubble sort to be O(n)

yangli