@@mtosity Usually a CS lecture on something like this would also include proofs for correctness, and time and memory complexity. Dont think it adds up to 30 minutes, but its obviously a lot more than what is shown here, which basically just the idea of the algorithm and an example.
I only recently found your channel and I'm finding your style and clarity to be especially effective for my learning. Just wanted to let you know how much I've been appreciating your content. Thanks!
Hello, i'm a student from the UK and my course requires me to learn a lot of the sorting algorithms that you have shown. Usually, only resources from people specifically covering the course is helpful, but these visual aids have been really effective and engaging, so thanks so much
Thanks for the explination. I wanted to point out that you can right much more effecient code: for i = 0 to n-1 for j = 0 to n-i-2 if array[j] > array[j+1] swap(array[j], array[j+1])
Very nice and to-the-point videos, thank you! A small note: bubble sort would perform better if n was decreased after each iteration (reflecting the fact that the last element is in its final position) and if we keep track of whether swaps have been made or not during a round (if not, we can just terminate).
And I think also every even iteration a bubble of small elements to the left will be good for a case that a small element is on the right side of the array.
the best optimization is setting your outter loop stop index to be the last swapped index of your inner loop. This makes it more naturally adaptive than keeping track of a swaps made boolean
Thanks Michael. Great job! But I guess pseudu code is wrong. It may be: for (int i = 0; i < array.length; i++) { for (int j = 0; j < array.length - 1 - i; j++) { if (less(array[j + 1], array[j])) exchange(array, j, j + 1); } }
@@jesusbojorquez2252 why? i starts with 1. First round you need to compare 6 times. That is N-1 Second you compare 5 times. That is N-2 Overall you have to do this 6 times (Not an insult, I am probably just don't get it)
@@kingcookie3920 I wrote N - i - 1 because if you look at the second for it goes from 0 to N -1, so when j == N - 1 it will compare a[N - 1] with a[N] which doesn't exist in the array. "FIrst round you need to compare 6 times" yes that's right but remember that the second for start from 0 so you don't need to go to N-1 you just need to go to N - 2.
Hello, i just eant to thank you for you effort in this short videos I have adhd and I always find it so hard to understand CS concepts such as datastructers and long videos don't work for me at all also I am a visual learner so, I'm really thankful!
Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order and it arranges them in increasing order.#IISH 11CSHLIC
The bubble sort method is a nice and simple method of sorting an array. It however looks to be very time consuming and inefficient as it would have to run almost as many times as the size of the array and it would be highly inefficient with larger arrays. #IISH11CSHLIC
ООООО, НАКОНЕЦ Я ПОНЯЛ ЭТОТ МОМЕНТ!!! То, что при первом прохождении цикла, большее число однозначно отсортируется и будет стоять в конце массива, из-за чего можно не проводить последующие проверки с ним
@michael, Thanks for the video, but shouldn't the second FOR loop be "for j from 0 to N-2". i.e till the second last element. Because if it reaches "N-1" i.e the last element then j+1 = N which will give out of bound error.
you are correct the values should be, i < nSize - 1 ( as i reaches nSize -1 , array will be sorted) j < nSize - i - 1 ( after i iterations, the last i elements are already sorted)
This psuedocode works, but it's literally doing twice the number of iterations it needs to, and this is wasteful code. It should be: For i = N-1 to 0 For j = 0 to i if a[j] < a[j+1] swap(a[j], a[j+1]) If after the first pass of j, the highest value in the array will be sitting in N. Knowing this, the second pass of j should terminate one space earlier, which will happen when i decrements toward 0.
#IISH 11CSHLIC The video helped me understand the process of bubble sorting and how the iteration works. It is a comparison of consecutive variables that gives the right form of number as the end result.
So bubble sort is a bit like the opposite of selection sort, isn't it? Since with selection sort, you have a sorted partition on the left at any given iteration, and with bubble sort you have a sorted partition on the right at any given iteration.
Great video! im doing GCSE computer science and i was just wondering what would an exam style question look like? would it simply ask to sort these numbers using a bubble sort (show your working) or breifly explain what a bubble sort does? thankyou
From @interviewkickstart I learned that, Its start comparison from right to left. So second for loop, For j from N to i Everything looks similar but here heavy element sorted at right. And Interviewkickstart video , in every steps lighter elements sorted at left
I would say the pseudo code isnt optimal as you dont need to check the last element of each itteration again. i would change it to this For i from 1 to N For j from 0 to N - i // the 1 to i instead if a[ j ] > a[ j+1] swap ( a[ j ], a[ j + 1] )
@@yahavx That's my point. You only have to iterate an array N times and not n^2 times. You have mentioned that "worst case of n^2 is also the best case" which is not correct or I have misunderstood your statement.
for an strange reason, running this pseudocode in python has a bug, I don't know why, but comparing 2 elements of the list, for example: 4>23, returns TRUE, because. it seems to be comparing only the first digit (4>2), I solved it by converting the current value and the next value to integer before comparing, does anyone know why this happens?
I know how to do the problem but I don't know how to tell the computer how long I want this process to continue. Do you have any suggestion of books to read or watch?
After completing a 30 minutes lecture on the topic this video is like a dessert after dinner.
These videos are great, 30mins of my lecture summarized in 2mins lol
30 minutes to explain bubble sort? Really?
@@mtosity Usually a CS lecture on something like this would also include proofs for correctness, and time and memory complexity. Dont think it adds up to 30 minutes, but its obviously a lot more than what is shown here, which basically just the idea of the algorithm and an example.
True😂
In min😂 2X
wait u guys are learning this in uni???
Love this visual way of learning. Thank you for the work put into this
ye
Ah
I only recently found your channel and I'm finding your style and clarity to be especially effective for my learning. Just wanted to let you know how much I've been appreciating your content. Thanks!
I appreciate you watching, thank you!
His two minutes of silent teaching was better than an hour of our lecturer's class.
Hello, i'm a student from the UK and my course requires me to learn a lot of the sorting algorithms that you have shown. Usually, only resources from people specifically covering the course is helpful, but these visual aids have been really effective and engaging, so thanks so much
glad the videos helped! thanks for the note.
I am a visual learner so I found this extremely helpful!
Thanks for the explination. I wanted to point out that you can right much more effecient code:
for i = 0 to n-1
for j = 0 to n-i-2
if array[j] > array[j+1]
swap(array[j], array[j+1])
amazing video - short, precise, and explains very well
@@Raum_Raum_Raum_Raum damn why so toxic
lmaoooo i cant believe i managed to understand what i have been struggling with the whole semester in 2 minutes. thanks man
Very simple and concise way to explain this algorithm. Keep up the good work and looking forward to more videos.
Shush bitch
Very nice and to-the-point videos, thank you! A small note: bubble sort would perform better if n was decreased after each iteration (reflecting the fact that the last element is in its final position) and if we keep track of whether swaps have been made or not during a round (if not, we can just terminate).
I was looking for this explanation that's how simple it is for some people. Two sentences to explain what is going on.
And I think also every even iteration a bubble of small elements to the left will be good for a case that a small element is on the right side of the array.
the best optimization is setting your outter loop stop index to be the last swapped index of your inner loop. This makes it more naturally adaptive than keeping track of a swaps made boolean
Thanks, I cleared my exam easily by watching this
now THIS is the best bubble sort guide ever
Thanks for a clear and simple video! It's Helping for my GCSE this May. Some people just overcomplicate these sort methods.
Very helpful, have a test in 2 days and know almost everything on this topic
According to your code, Number of comparisons is n(n-1) but it can be reduced to n(n-1)/2 by setting j upto n-i-1
i was thinking about the same
thanks for the confirmation
I have an exam soon, this video really helped!
i have exam tomorrow, this video helped me revise bubble , thanks
crush it!
I have watched your all videos several times whenever i need to review the algorithm, " You Are Definitely A God Of Algorithm"
Incredible video, you're style of teaching is very easy to understand.
Best video I've seen to explain bubble sort, thank you!
you're videos are more helpful than other videos that are 30 to 40min long and yet at the end still are confused.
This animation absolutely made me understand the bubble sort
Thankyou from saving me from watching 1 hour lecture, when I am in rush before exams
Thanks Michael. Great job! But I guess pseudu code is wrong. It may be:
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array.length - 1 - i; j++) {
if (less(array[j + 1], array[j]))
exchange(array, j, j + 1);
}
}
yes both are correct but yours is more optimized
Thanks! No music and no trash!
for i from 1 to N: # N-1 iterations to sort a N-length list
for j from 0 to N-i: # after i iterations ,the last i elements are sored
Best algo channel on youtube.
Thanks dude, this shorts videos are saving me for my algoritm exam!
Thanks!
Bruh is this really what took my professor most of the class trying to explain😭 thank you so much for this
I literally coded it after u explaining it to me. This helped soo much!
Those saying that pseudocodes is wrong are incorrect, you can have another implementation that's right too
Thank you so much for amazing videos! Great repetition before exams.
All your sort videos were awesome!!! Thank you so much bc I needed it for my final tmw lol
This channel is underrated man!
excellent explanation.........very simple and easy to understand
Awesome simple and straight to the point - subscribed!
This was such a good video, some things just need visualizations.
Thanks man. Wish me luck for my test tomorrow
Thank u, didnt have time for big explanations
Awesome videos, great refreshers before finals
💪🏼❤️
so much better than my 3 hour lectures
i like these short vids
to the point and no padding like those other shitty ass vids
thank you kind sir
the pseudocode works but I would do "N-i" instead of "N-1"
N - i - 1
@@jesusbojorquez2252 why? i starts with 1.
First round you need to compare 6 times. That is N-1
Second you compare 5 times. That is N-2
Overall you have to do this 6 times
(Not an insult, I am probably just don't get it)
@@kingcookie3920 I wrote N - i - 1 because if you look at the second for it goes from 0 to N -1, so when j == N - 1 it will compare a[N - 1] with a[N] which doesn't exist in the array. "FIrst round you need to compare 6 times" yes that's right but remember that the second for start from 0 so you don't need to go to N-1 you just need to go to N - 2.
Just an ordinary boy here just to read these comments, i’m not crazy to argue with a king specially with jesus.
You're doing an advanced bubble pass, a normal one still does the rest even though you know the last is known.
Hello, i just eant to thank you for you effort in this short videos I have adhd and I always find it so hard to understand CS concepts such as datastructers and long videos don't work for me at all also I am a visual learner so, I'm really thankful!
you're welcome!
Awesome. Short, sweet, simple
Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order and it arranges them in increasing order.#IISH 11CSHLIC
I love having to put the video in 2x speed. This should be a 20 second video
Go as fast as you need :) I talk slow.
The bubble sort method is a nice and simple method of sorting an array. It however looks to be very time consuming and inefficient as it would have to run almost as many times as the size of the array and it would be highly inefficient with larger arrays. #IISH11CSHLIC
prolly usefull in special cases
Best video on bubble sort
Finally understand it, thanks so much
Thank you! This really was helpful.
ООООО, НАКОНЕЦ Я ПОНЯЛ ЭТОТ МОМЕНТ!!!
То, что при первом прохождении цикла, большее число однозначно отсортируется и будет стоять в конце массива, из-за чего можно не проводить последующие проверки с ним
Nice video! Helpped I lot to teach this
@michael, Thanks for the video, but shouldn't the second FOR loop be "for j from 0 to N-2". i.e till the second last element.
Because if it reaches "N-1" i.e the last element then j+1 = N which will give out of bound error.
you are correct
the values should be,
i < nSize - 1 ( as i reaches nSize -1 , array will be sorted)
j < nSize - i - 1 ( after i iterations, the last i elements are already sorted)
I like colors you made.
this was very helpful, Thank you!
De nada!
Wouldnt it be more efficient if it didnt look at the number combos that didnt change
Brilliant explanation!!
Please make a video on Radix sort.
Great video! Thank you so much.
Perfection. Thank you.
Very helpful thanks for the video!
This was great. Thank you!
Thank you so much, very helpful!
Simply, awesome...
great and efficient to learn like this
Nice video!! It helped me a lot
my teacher showed us this dumb ass dance thing and I was like WTF IS THIS GARBAGE. this is so much more helpful thank you. I actually get it now
Just what I needed!
This psuedocode works, but it's literally doing twice the number of iterations it needs to, and this is wasteful code. It should be:
For i = N-1 to 0
For j = 0 to i
if a[j] < a[j+1]
swap(a[j], a[j+1])
If after the first pass of j, the highest value in the array will be sitting in N. Knowing this, the second pass of j should terminate one space earlier, which will happen when i decrements toward 0.
#IISH 11CSHLIC The video helped me understand the process of bubble sorting and how the iteration works. It is a comparison of consecutive variables that gives the right form of number as the end result.
Great explanation!
So bubble sort is a bit like the opposite of selection sort, isn't it? Since with selection sort, you have a sorted partition on the left at any given iteration, and with bubble sort you have a sorted partition on the right at any given iteration.
Nicely done!
Bubblesort is basically the MOST BASIC SORT EVER
Thank you it was very helpful
Great video! im doing GCSE computer science and i was just wondering what would an exam style question look like? would it simply ask to sort these numbers using a bubble sort (show your working) or breifly explain what a bubble sort does? thankyou
In my experience, it's likely the first one.
One question might be what will the last two numbers be after the first iteration (the answer would be 1 , 9)
humans hav voice for reason : nice work
Currently done with 2h lecture, now time for 2h lab. Leave me alone bubble sort!
You're great. Thank you
Bubble sort Javascript code:
function bubbleSort(arr) {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
let temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
return arr;
}
very good, thank you❤️👍
From @interviewkickstart I learned that,
Its start comparison from right to left.
So second for loop,
For j from N to i
Everything looks similar but here heavy element sorted at right. And Interviewkickstart video , in every steps lighter elements sorted at left
I would say the pseudo code isnt optimal as you dont need to check the last element of each itteration again.
i would change it to this
For i from 1 to N
For j from 0 to N - i // the 1 to i instead
if a[ j ] > a[ j+1]
swap ( a[ j ], a[ j + 1] )
is it me or this is probably the slowest sorting algo?
thanks for a more clear explanation
Guys is N-1 not N-i just saying its the last value not the array size a[i]
Small typo: I believe in the pseudocode, the j loop should be from 0 to N-i
you saved me, thanks a lot man
Just seen this before 1 hour of exam 😂😂
The numbers were exchanging from left to right by arrenging in order like 453621=123456
Subscribed, thanks!
Should mentioned that the worst case of n^2 is also the best case. Great video though
best case is O(n)
@@RahulSiyanwal No because you iterate the array N times whatsoever. even if the array is already sorted. Maybe you're confusing with insertion sort
@@yahavx just update a flag hasSwaped and exit on false..
would that give O(n) 4 best case?
@@yahavx That's my point. You only have to iterate an array N times and not n^2 times. You have mentioned that "worst case of n^2 is also the best case" which is not correct or I have misunderstood your statement.
You are using nested for loops. Their for its O(n^2) best and worse
So helpful thank you!
so, essentially, the worst case scenario is where it's already sorted but in reverse order, right?
Simple and understandable
thanks for helping me pass an exam
for an strange reason, running this pseudocode in python has a bug, I don't know why, but comparing 2 elements of the list, for example: 4>23, returns TRUE, because. it seems to be comparing only the first digit (4>2), I solved it by converting the current value and the next value to integer before comparing, does anyone know why this happens?
I know how to do the problem but I don't know how to tell the computer how long I want this process to continue. Do you have any suggestion of books to read or watch?
This is amazing