Комментарии:
Pls tell me a good book for java for beginners
Ответитьmay god bless you
ОтветитьClearly amazing, wow, while loop was clearly making sense! Thank you for explaining this sorting algorithm
ОтветитьGreat explanation, great video!
ОтветитьI don't know how it happened, but I sorted a million-element int array with bubble sort in under 200 ms. It seems it's not that slow after all 🤔
Ответитьwooow
Ответитьomg, you explained this very good. I subscribed to you now
ОтветитьThanks, you’re great!
ОтветитьJohn the man ! <3
ОтветитьI think you should not print the elements of the array if you want to check the running time for the algorithm
most of the time is in writhing the elements to the screen
what about from highest to lowest? badly need :(
ОтветитьThat's the best implementation of bubble sort I have ever seen
Ответитьprivate static void printArray(int[] numbers){
for (int i = 0; i < numbers.length; i++) {
System.out.println(numbers[i]);
}
} How to print the elements of the array in the same line with a semicolon seperator?
Thank you :)
we need to address the elephant in the room -> Kramer painting :) Your channel is pure gold, keep up the good work!
ОтветитьFantastic! Fantastic!! Fantastic video John!!!
ОтветитьI think bubble sort is efficient in terms of memory since it does require extra memory
ОтветитьMan definitely something I have been looking for
ОтветитьDoes anyone know how bubble sort would work for a string data type??
ОтветитьHonestly this made more sense than when my professor briefly explained how it worked then left it at that.
ОтветитьThank you
ОтветитьThanks :)
Ответитьgoing to pass my Algos class because of this channel! Love your channel my friend.
ОтветитьThis visual representation is the best thing ever
ОтветитьBro we need a lesson on selection sort,
And another on comparision between selection and insertion sort,
And lastly overall comparison between all other sorting algorithm (insertion, selection, bubble, quick, merge, heap) in terms of time, space complexity and when to use
ty
ОтветитьIs that Kramer's photo on the bottom right ?
ОтветитьPretty cool,
I like it!
👍
Do you have playlist for sorting algorithms?
ОтветитьAt first I didn't want to care abt this BIG O of N² mentions
But now... 😐 I'm thinking it's kind of important
I can do it 🙂Copium
Hi genuine question
when you set the swappedSomething = false;
would that mean it will break through the while loop and never go to the for loop, Im fairly new to programming so im a lil bit confuse abt it
i believe bubblesort is either bad explained or bad animated, actually compares first element to all, then second element to all from second element, then third element from all from third element and so on... not in pairs.
ОтветитьIf don't undertand something I don't give up, I just find another source of the same information. That's how I found your channel.
From a non native speaker that's sick of indians
Thank you!
i love you man
Ответитьvery vivid, thank you ,John
ОтветитьI've question about this algorithm. When we do first loop the max element will be at the end of array. Can we decrement loop by 1 on every while loop. Shortly, I want to say that we can neglect the last element and in every while loop we can write loop like :
int length = list.length;
while (sorted!= true)
for(int i = 0;i < length-1;i++){
do something();
length -= 1;
}
please correct me if i've mistaken
Just something to think about. Since every time you go through the for statement, the last number is in the correct place, you only have to go through it to "length -1" once and the next time is "length - 2" and you'd be doing one less comparison and loop each time, so wouldn't the complexity be less?
If you still have the source code, would you make the change and let me know if it makes a difference? Obviously with the way you have it set up, you'd have to generate a "permanent" array and copy it to sort it both ways.
Just a thought - and it's easy for me to hand out assignments to someone who's just trying to advance knowledge on the internet.
Thanks for the tutorial.
Very clear explanation i even enjoyed learning by watching it..
ОтветитьVery carefully explained. Thank you very much for the video
ОтветитьGreat explanation...
ОтветитьMake a video to generate random numbers without using Randam class
Ответить🖤
ОтветитьHere's a little improvement to the Bubble Sort implementation:
For every loop, there will be one highest element put to the rightmost of the array. So instead of hardcoding the numbers.length, put it in some variable before for-loop (ex: index = numbers.length). At the end of the for-loop block, decrease the index by one (index--). Because, you don't need in anyway checking the rightmost elements that have been checked in the previous loop. Those elements are already sorted.
Here's the implementation:
public static String bubbleSort(int[] numbers) {
boolean swappedSomething = true;
while(swappedSomething ) {
swappedSomething = false;
int index = numbers.length-1;
for (int i = 0; i < index; i++) {
if(numbers[i] > numbers[i+1]) {
swappedSomething = true;
int temp= numbers[i];
numbers[i] = numbers[i+1];
numbers[i+1] = temp;
index--;
}
}
}
I hadn't seen this approach to the Bubble Sort. We did it as a loop inside of another loop.
This one seems cleaner.
is this a late april fools? you know that after each 'bubble' there will be one more ordered element? instead of a while just use 2 for loops, the first one moves the end point back and the second one moves the 'bubble'
Ответитьa beautiful piece of code ! 😍
ОтветитьIn java it takes time to even print on stdout...program will run faster without print
ОтветитьYou could also just use another int to declare the last switched index, so you can just leave the rest, sorted array untouched, this should safe you a lot of time with big arrays, because it just gets at least one iteration smaller each round.
Ответить