Learn Bubble Sort in 7 minutes 🤿
ฝัง
- เผยแพร่เมื่อ 23 พ.ค. 2021
- Data structures and algorithms bubble sort tutorial example explained
#bubble #sort #algorithm
// bubble sort = pairs of adjacent elements are compared, and the elements
// swapped if they are not in order.
// Quadratic time O(n^2)
// small data set = okay-ish
// large data set = BAD (plz don't)
music credits 🎼 :
===========================================================
Twelve Speed by - Slynk • Slynk - Twelve Speed (...
===========================================================
Up In My Jam (All Of A Sudden) by - Kubbi / kubbi
Creative Commons - Attribution-ShareAlike 3.0 Unported- CC BY-SA 3.0
Free Download / Stream: bit.ly/2JnDfCE
Music promoted by Audio Library • Up In My Jam (All Of A...
=========================================================== - วิทยาศาสตร์และเทคโนโลยี
public class Main{
// bubble sort = pairs of adjacent elements are compared, and the elements
// swapped if they are not in order.
// Quadratic time O(n^2)
// small data set = okay-ish
// large data set = BAD (plz don't)
public static void main(String[] args) {
int array[] = {9, 1, 8, 2, 7, 3, 6, 4, 5};
bubbleSort(array);
for(int i : array) {
System.out.print(i);
}
}
public static void bubbleSort(int array[]) {
for(int i = 0; i < array.length - 1; i++) {
for(int j = 0; j < array.length - i - 1; j++) {
if(array[j] > array[j+1]) {
int temp = array[j];
array[j] = array[j+1];
array[j+1] = temp;
}
}
}
}
}
Hello, can i get this code?
Practicing...
Ascending order
public class Main
{
public static void main(String[] args) {
int array[] = {7,3,2,1,4,0,8,6,5};
bubbleSort(array);
for(int i: array){
System.out.print(i);
}
}
public static void bubbleSort(int array[]){
for(int i = 0; i < array.length - 1; i++){
for(int j = 0; j < array.length - i -1; j++){
if(array[j] > array[j + 1]){
int temp = array[j];
array[j] = array[j+1];
array[j+1]= temp;
}
}
}
}
}
*************************
Descending order
public class Main
{
public static void main(String[] args) {
int array[] = {7,3,2,1,4,0,8,6,5};
bubbleSort(array);
for(int i: array){
System.out.print(i);
}
}
public static void bubbleSort(int array[]){
for(int i = 0; i < array.length - 1; i++){
for(int j = 0; j < array.length - i -1; j++){
if(array[j] < array[j + 1]){
int temp = array[j];
array[j] = array[j+1];
array[j+1]= temp;
}
}
}
}
}
@@andreamixvlog7478yeah you can get it
The comparison with the two cups was really intuitive! I wish someone had explained me variable swapping with that example.
it's been less than 10 minutes since this masterpiece was uploaded and here's already a dislike? WHO ARE YOU??!
losers!
@@BroCodez yes sir
@@BroCodez🥲 I thought u meant not losers at first
These videos are great. Really helpful for my studying, thank you
U r videos are my go to for all the sorting algos, Thank you for making these, Great help, Keep up the great work!
Bro is the best when it comes to explaining. I hope this guy blows up all over yt. I will support him
I still come back to this video from time to time to rehash my BubbleSort.
Thanks BRO!
legit only channel I have notifications on for, lifesaver!
thanks Poromoro! I'm glad these videos are helping
As always... excellent videos! Thanks!
Great explanation, thank you so much.
I love u!!!! Thank u for making the concept so clear n understandable💝
Bro you are just amazing , i really appriciate your works .. Please keep going
thanks for watching!
You are saving my life in cs classes. Thank you so much.
sweet! I'm glad the videos are helping!
always waiting for your video !!! keep doing this , love u
Thanks! I will continue
I'm watching your videos from Brazil and I want to thank you for taking the time to teach us. It was very didactic to understand your explanation. Thank you very much.
Thank you very much bro, you put so much time and effort into your videos!
Thank you. It was so helpful!!
thank you for the video, very easy to understand with your explanation
Really can't be better than this, thanks so much it was great tutorial❤❤
Very helpful video, thank you!
Good explantation, Thanks for sharing
Thanks from Egypt❤🔥
Great Video mate!
Ey Brooooo ... i love you man ... not even my uni lecturer explained sorting this well .. saw this video 1 day prior to my exam and it helped meee soo much.. really appriciate BROOO ..Much Love from Sri Lanka ❤
💯 thank you!
Thanks from Italy!
you are a truly gigachad... really golden video. keep going!
I'm from Colombia and I can understand all with this video, thx u (I love the manual example)
Clear and Concise. Thanks.
Thanks for watching John!
Really helpful video. I could not understand the concept of bubble sort before but now i do and it has helped me code my programs better thanks bro
very useful, thanks!
Many thanks!
thank you for these perfect video.
Amazing, thanks alot
thank you!
Thank you bro!
Like always...legendary!
Thanks Nikitos!
Thanks Mate!!
this helped me out thank you
Thanks for watching Qwikz!
you are great, just 15k subs away from the milestone! congrats
Yeah that's coming up soon!
very well done!
thx man for the amazing video , I wanted to note that since the inner loop has 8 elements to be compared and the last element won't get compared because the second element then will already be sorted, so for that the outerloop should be array.length - 2 right ?
thank you!!!
Thanks!
You're really saving my ass studying for that computer science exam - thanks bro!
great man
Thank you
I know it already but I appreciate your effort. I currently know bubble sort, selection sort, insertion sort, binary and linear search as per my school syllabus. I will be waiting for your quick sort tutorial, I seriously want to learn it.
quicksort will be coming up soon I believe
thank you (:
it was perfect.
all of it
thanks man
thanks for clarify this
You've got it sorted out.😎
thank you so much, it makes me easy, cause I watched alot of tutorials but don't understand.
yesterday I bought a C# course on udemy, the first video is talking how to make a Bubble sort, but i don't understand.
then my mind said: go on yotube, may be you can find a good teacher that makes simply to this fucking Bubble sort.
then i got you.
Now i understand the Bubble sort.
thank you so much..
For the second for-loop
for(int j = 0; j < array.length - i - 1; j++)
Why must we subtract i and one? I understand why we need to subtract one but why i?
I know it's kind of late, but I'll reply anyway in case someone has the same question. We subtract i, so that way we won't check the numbers that are already sorted!
than you!!
Thanks
thanks bro :D
Learnt thx
Nice
amazing
the best channel on youtubeeee
Thanks bro!
Thank You Bro! YOU ARE GREAT MY FRIEND! (People who dislikes are not from Computer Science background! LOL)! Well, I'm comfortable in Python programming. So, I didn't watch your Java code. But, your explanation is so perfect that it was building an easy understanding about the algorithm. So nicely explained! Bro, Do you also solve leet code problems?
Perfect 👌🏼
thanks Remol!
You're the best
Bro thanks just what i was looking
awesome! Thanks for watching Yehan!
tHank you broooo
Thank you for the algorithm!
Thanks for commenting to help with the TH-cam algorithm!
@@BroCodez Bro, can you do quick sort , please?
holy moly, way better than my professor lol :))
Bro is the goat 🐐
Legend.
Thank you ;)
thanks for watching Yu!
Thank you for your video. I think you need to break the loop if the array is already sorted for efficiency.
Thanks for video
np! Thanks for watching EMbo!
New bro here loved you video brooooo🤘🤘🤘
Great video! Please explain QuickSort , Heap and Binary Trees!!
Thanks Abdul! We'll get to those topics eventually!
I will savour this moment that does not involve recursion
Bubble sort is a very easy algorithm to implement, but is quite inefficient with large data sets
hey you, thank you
Thank You
Thanks for watching Vehan!
@@BroCodez 😊❤
Great video
Thanks Michal!
I love you bro thanks 😘💙❤️😘
THanks bro!
you deserve more subscribers.
thanks Mohit!
Great job..
Please Start complete video series on node KS as back-end technology..
maybe! I'll let you guys vote on future topics when I release polls
👍👍👍
Defeat the algorithm, Bros.
Great videos, you are very helpfull! One question, in second for loop, can we write "int j = i" instead of 0, because we do not want to compare elements that are already sorted?
he already does that
but its not the first i elements that are sorted
its the last i
Everyone does not share information's easily and free, mostly want money, Thanks for sharing free INFORMATIONS BRO
no problem! Thanks for watching Saber
hi.can you start from the end of the table to compare the elements or is it wrong?(Python)
top
I Hope you can do a PHP cours i Really like the way that you teach you are amazing
maybe! I'll let you guys vote on future topics
Very easy to understand, but I wish u made those tutorial in C.
oooo yeahhh
Good video explanation of the Bubble Sort algorithm. Would it be possible to make a video of binary tree algorithm with the different ways of visiting the tree structure plus how to insert, delete and search for a node in the tree? It would be very educational. Thank you.
I'm planning binary trees for a future video
i dont understand the "J" loop, why do you substract "i"? could someone explain pls
I am happy to announce that I will be building a complementary video series (Algorithmic Complexity Analysis) that analyzes many of the defined concepts within your talks to demonstrate it using a rigorous mathematical framework that describes algorithms on a meta-level and forms the perfect combination, when watched in conjunction with your video series
Me watching this as i have an exam tomorrow (im saved by this chad)
ну ниплоха сделал мне нравится
Sensei Bro Miyagi:)
haha! I love the Karate Kid reference!
Hey! bro or guys, why are u using a nested loop? still didnt get it