Learn Bubble Sort in 7 minutes 🤿

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ก.ย. 2024
  • 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...
    ===========================================================

ความคิดเห็น • 228

  • @BroCodez
    @BroCodez  3 ปีที่แล้ว +114

    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;
    }
    }
    }
    }
    }

    • @andreamixvlog7478
      @andreamixvlog7478 ปีที่แล้ว +1

      Hello, can i get this code?

    • @joyceasante8292
      @joyceasante8292 ปีที่แล้ว +4

      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;
      }
      }
      }
      }
      }

    • @koinahotahai
      @koinahotahai 9 หลายเดือนก่อน

      ​@@andreamixvlog7478yeah you can get it

  • @dhoneybeekingdom7889
    @dhoneybeekingdom7889 ปีที่แล้ว +25

    The comparison with the two cups was really intuitive! I wish someone had explained me variable swapping with that example.

  • @김우솔-j3l
    @김우솔-j3l 3 ปีที่แล้ว +13

    You are saving my life in cs classes. Thank you so much.

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว +6

      sweet! I'm glad the videos are helping!

  • @jaykay8426
    @jaykay8426 2 หลายเดือนก่อน +4

    Out of all the basic ways of sorting, this is the slowest of the basic ways to sort

  • @Zippo_1234
    @Zippo_1234 ปีที่แล้ว +11

    These videos are great. Really helpful for my studying, thank you

  • @ashmikanln3110
    @ashmikanln3110 ปีที่แล้ว +4

    U r videos are my go to for all the sorting algos, Thank you for making these, Great help, Keep up the great work!

  • @poromoro2414
    @poromoro2414 3 ปีที่แล้ว +4

    legit only channel I have notifications on for, lifesaver!

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว

      thanks Poromoro! I'm glad these videos are helping

  • @DetCoAnimeFan
    @DetCoAnimeFan 3 ปีที่แล้ว +21

    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.

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว +12

      quicksort will be coming up soon I believe

  • @GamingPro-xn4hy
    @GamingPro-xn4hy ปีที่แล้ว +1

    Bro is the best when it comes to explaining. I hope this guy blows up all over yt. I will support him

  • @sakuriosky1573
    @sakuriosky1573 10 หลายเดือนก่อน +3

    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?

    • @jellojoy2977
      @jellojoy2977 7 หลายเดือนก่อน

      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!

    • @pupper5580
      @pupper5580 หลายเดือนก่อน +1

      we subtract 1 so there wont be overflow from the array. You can avoid using -1 by doing the following steps: 1) start the j-loop from 1. 2) when you do comparison, you do arr[j-1] and arr[j] comparisons. Using this version of the loop might be more intuitive to understand.

  • @leonardopensador
    @leonardopensador 6 หลายเดือนก่อน

    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.

  • @moum.a8130
    @moum.a8130 3 ปีที่แล้ว +32

    Bro you are just amazing , i really appriciate your works .. Please keep going

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว +10

      thanks for watching!

  • @mohamedabdirizakahmed3539
    @mohamedabdirizakahmed3539 10 หลายเดือนก่อน +1

    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..

  • @Snowmanver2
    @Snowmanver2 2 ปีที่แล้ว +17

    Bubble sort is a very easy algorithm to implement, but is quite inefficient with large data sets

  • @andres9108
    @andres9108 4 หลายเดือนก่อน

    I'm from Colombia and I can understand all with this video, thx u (I love the manual example)

  • @ThEHUNtErCr9
    @ThEHUNtErCr9 5 หลายเดือนก่อน

    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

  • @aaronfernando5300
    @aaronfernando5300 ปีที่แล้ว

    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 ❤

  • @T-Rex0711
    @T-Rex0711 10 หลายเดือนก่อน +5

    Defeat the algorithm, Bros.

  • @MohammadJavadd
    @MohammadJavadd 4 หลายเดือนก่อน

    Really can't be better than this, thanks so much it was great tutorial❤❤

  • @aditya_asundi
    @aditya_asundi 3 ปีที่แล้ว +1

    you are great, just 15k subs away from the milestone! congrats

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว +2

      Yeah that's coming up soon!

  • @barelycodingtoday
    @barelycodingtoday ปีที่แล้ว

    I still come back to this video from time to time to rehash my BubbleSort.
    Thanks BRO!

  • @vancemccarthy2554
    @vancemccarthy2554 26 วันที่ผ่านมา

    I had been looking for bubble sort written in basic. I found BBC2 book with a sample program, but the code was messy.
    I managed to make easy to understand and I use it for personal applications. Like statistics.
    A list of names and their statistics - e.g. (height, weight, age ) and put in order by any list.

  • @DanielSmith-uj7rr
    @DanielSmith-uj7rr 2 ปีที่แล้ว +3

    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?

  • @thainguyenviet3267
    @thainguyenviet3267 3 ปีที่แล้ว

    always waiting for your video !!! keep doing this , love u

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว

      Thanks! I will continue

  • @kyawsanaung2019
    @kyawsanaung2019 4 หลายเดือนก่อน

    Thank you for your video. I think you need to break the loop if the array is already sorted for efficiency.

  • @quoilaa903
    @quoilaa903 2 หลายเดือนก่อน

    all I keep hearing is bulbasaur 😆Thanks for the video!!

  • @dankmemequeen9581
    @dankmemequeen9581 ปีที่แล้ว

    Thank you very much bro, you put so much time and effort into your videos!

  • @BN-cr3el
    @BN-cr3el 3 ปีที่แล้ว +2

    💯 thank you!

  • @wolfskind9135
    @wolfskind9135 3 ปีที่แล้ว

    You're really saving my ass studying for that computer science exam - thanks bro!

  • @bagnotneeded
    @bagnotneeded 2 ปีที่แล้ว

    you are a truly gigachad... really golden video. keep going!

  • @junialdy
    @junialdy ปีที่แล้ว

    thank you for the video, very easy to understand with your explanation

  • @qwikz5389
    @qwikz5389 3 ปีที่แล้ว +1

    this helped me out thank you

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว +1

      Thanks for watching Qwikz!

  • @codeammar
    @codeammar ปีที่แล้ว +1

    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 ?

  • @joelpose7269
    @joelpose7269 ปีที่แล้ว +1

    i dont understand the "J" loop, why do you substract "i"? could someone explain pls

  • @sahinyusifli9756
    @sahinyusifli9756 ปีที่แล้ว

    Thank you. It was so helpful!!

  • @aleksandarduncevic9548
    @aleksandarduncevic9548 11 หลายเดือนก่อน +1

    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?

    • @poparobertandrei1698
      @poparobertandrei1698 10 หลายเดือนก่อน

      he already does that
      but its not the first i elements that are sorted
      its the last i

  • @BruceNguyen1999
    @BruceNguyen1999 หลายเดือนก่อน

    Thank bro code you is my hero about progamming thanks bro

  • @CuriosityUnleashed-c6i
    @CuriosityUnleashed-c6i 2 ปีที่แล้ว

    Great explanation, thank you so much.

  • @gabrielcasanova7034
    @gabrielcasanova7034 2 ปีที่แล้ว +1

    Hey! bro or guys, why are u using a nested loop? still didnt get it

  • @aleacevedo1016
    @aleacevedo1016 ปีที่แล้ว

    As always... excellent videos! Thanks!

  • @xeahmedrefat2972
    @xeahmedrefat2972 ปีที่แล้ว

    Thanks from Egypt❤‍🔥

  • @sabermmirza
    @sabermmirza 3 ปีที่แล้ว

    Everyone does not share information's easily and free, mostly want money, Thanks for sharing free INFORMATIONS BRO

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว

      no problem! Thanks for watching Saber

  • @jerrypolemica2704
    @jerrypolemica2704 ปีที่แล้ว

    Thanks from Italy!

  • @jdserrato3792
    @jdserrato3792 11 หลายเดือนก่อน

    I will savour this moment that does not involve recursion

  • @plankalkulcompiler9468
    @plankalkulcompiler9468 ปีที่แล้ว

    Very helpful video, thank you!

  • @johnhansen4794
    @johnhansen4794 3 ปีที่แล้ว

    Clear and Concise. Thanks.

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว

      Thanks for watching John!

  • @dharmeshajudiya1709
    @dharmeshajudiya1709 ปีที่แล้ว

    Good explantation, Thanks for sharing

  • @lambdadotjoburg
    @lambdadotjoburg 5 หลายเดือนก่อน

    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

  • @jamiebenish1534
    @jamiebenish1534 3 ปีที่แล้ว +3

    Hello brother :)

  • @StefanosFragoulis
    @StefanosFragoulis ปีที่แล้ว

    Great Video mate!

  • @Tomteluva82
    @Tomteluva82 5 หลายเดือนก่อน

    very useful, thanks!

  • @preet6095
    @preet6095 2 ปีที่แล้ว

    Explanation of j< array.length-i-1 ? please...

    • @morhakak1907
      @morhakak1907 2 ปีที่แล้ว +1

      After the first iteration the highest number will ended up in the highest position. so, in the next iteration we don't need to check again for that number (he's at the right position).
      After the second iteration the second highest number will ended up in the second highest position, so we don't need to check again for that number or the number in the highest position.
      And so on for the rest of the iterations.

  • @jacklagos936
    @jacklagos936 ปีที่แล้ว

    Many thanks!

  • @sadman6852
    @sadman6852 7 หลายเดือนก่อน

    Thank you bro!

  • @envektro2519
    @envektro2519 3 ปีที่แล้ว +2

    can you do this for every sorting algorithm? thanks in advance

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว +3

      I'll try

  • @geografixxxx
    @geografixxxx ปีที่แล้ว

    Very easy to understand, but I wish u made those tutorial in C.

  • @abdulmoiz5311
    @abdulmoiz5311 3 ปีที่แล้ว +1

    Great video! Please explain QuickSort , Heap and Binary Trees!!

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว +3

      Thanks Abdul! We'll get to those topics eventually!

  • @anthonychiara6809
    @anthonychiara6809 8 หลายเดือนก่อน

    why is it j

  • @majdkinani587
    @majdkinani587 7 หลายเดือนก่อน

    Me watching this as i have an exam tomorrow (im saved by this chad)

  • @autosuggestionasshole9208
    @autosuggestionasshole9208 3 ปีที่แล้ว

    the best channel on youtubeeee

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว

      Thanks bro!

  • @alien_X1
    @alien_X1 3 ปีที่แล้ว +2

    Bring on modules in python pls bro sir

    • @alien_X1
      @alien_X1 3 ปีที่แล้ว +2

      Like making tools automation etc

  • @yehannk448
    @yehannk448 3 ปีที่แล้ว

    Bro thanks just what i was looking

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว

      awesome! Thanks for watching Yehan!

  • @IsaacAwad.04
    @IsaacAwad.04 3 หลายเดือนก่อน

    thanks man

  • @MeditateRelaxEtcetera
    @MeditateRelaxEtcetera 6 หลายเดือนก่อน

    You've got it sorted out.😎

  • @lazyknight1743
    @lazyknight1743 หลายเดือนก่อน

    DROP a COMMENT for this awesome video.

  • @muhammed__5
    @muhammed__5 9 หลายเดือนก่อน

    very well done!

  • @Omar-_-_
    @Omar-_-_ 2 ปีที่แล้ว

    Amazing, thanks alot

  • @ALBERTJOAQUINENSELADA
    @ALBERTJOAQUINENSELADA 10 หลายเดือนก่อน

    thank you!

  • @youcefmantas4944
    @youcefmantas4944 ปีที่แล้ว

    Thanks Mate!!

  • @MrLoser-ks2xn
    @MrLoser-ks2xn ปีที่แล้ว

    Thanks!

  • @nikitos2442
    @nikitos2442 3 ปีที่แล้ว

    Like always...legendary!

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว

      Thanks Nikitos!

  • @TITAN-sv5eg
    @TITAN-sv5eg ปีที่แล้ว

    thanks for clarify this

  • @admoonhermiz1
    @admoonhermiz1 11 หลายเดือนก่อน

    thank you!!!

  • @vehanhemsara9793
    @vehanhemsara9793 3 ปีที่แล้ว +1

    Thank You

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว +1

      Thanks for watching Vehan!

    • @vehanhemsara9793
      @vehanhemsara9793 3 ปีที่แล้ว

      @@BroCodez 😊❤

  • @_4p_
    @_4p_ ปีที่แล้ว

    it was perfect.
    all of it

  • @sakiszintros7782
    @sakiszintros7782 7 หลายเดือนก่อน

    hi.can you start from the end of the table to compare the elements or is it wrong?(Python)

  • @alinaseerideas2295
    @alinaseerideas2295 3 ปีที่แล้ว

    Great job..
    Please Start complete video series on node KS as back-end technology..

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว

      maybe! I'll let you guys vote on future topics when I release polls

  • @elbioiseas7366
    @elbioiseas7366 3 ปีที่แล้ว +2

    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.

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว +5

      I'm planning binary trees for a future video

  • @Dumb4Creepy
    @Dumb4Creepy 11 หลายเดือนก่อน

    can someone help me... why is it that we use " i < array.length - 1 " coz "

  • @tronganhnguyenthanh1157
    @tronganhnguyenthanh1157 9 หลายเดือนก่อน

    I have a mathmetics like that:
    let text = "AAAABBCCCDA"
    how do you convert this one to 4A2B3C1D1A" ?

  • @pjguitar15
    @pjguitar15 5 หลายเดือนก่อน

    for (int i = 0; i < array.length; i++) {
    for (int j = 0; j < array.length - 1; j++) {
    if (array[j] > array[j + 1]) {
    int temp = array[j];
    array[j] = array[j + 1];
    array[j + 1] = temp;
    }
    }
    }
    This code worked for me. Why? My second for loop doesn't subtract i from array.length.

  • @canadianbeast8671
    @canadianbeast8671 2 ปีที่แล้ว

    another simple implementation of bubble-sort algorithm
    public static void bubble(int[] arr) {
    int temp;
    for(int i=0; i

  • @MohitRaj-1712
    @MohitRaj-1712 3 ปีที่แล้ว

    you deserve more subscribers.

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว

      thanks Mohit!

  • @CSstudent_1001
    @CSstudent_1001 11 หลายเดือนก่อน

    Thank you

  • @learner8005
    @learner8005 ปีที่แล้ว

    New bro here loved you video brooooo🤘🤘🤘

  • @cashionsteven5695
    @cashionsteven5695 3 ปีที่แล้ว

    holy moly, way better than my professor lol :))

  • @amkiji2992
    @amkiji2992 3 ปีที่แล้ว

    I Hope you can do a PHP cours i Really like the way that you teach you are amazing

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว +1

      maybe! I'll let you guys vote on future topics

  • @Cristian-me9id
    @Cristian-me9id 7 หลายเดือนก่อน

    thank you (:

  • @meetprotrash3178
    @meetprotrash3178 3 ปีที่แล้ว +1

    I love you bro thanks 😘💙❤️😘

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว

      THanks bro!

  • @AlaEddineStudentMezdoud
    @AlaEddineStudentMezdoud 9 หลายเดือนก่อน

    great man

  • @LoveTaiwan678
    @LoveTaiwan678 3 ปีที่แล้ว

    Thank you ;)

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว +1

      thanks for watching Yu!

  • @wallstreetbets7741
    @wallstreetbets7741 2 ปีที่แล้ว

    Learnt thx

  • @ФайзуллаАсатуллаев
    @ФайзуллаАсатуллаев ปีที่แล้ว

    Thanks

  • @indigo_diary
    @indigo_diary 11 หลายเดือนก่อน

    than you!!

  • @sanjays9082
    @sanjays9082 3 ปีที่แล้ว

    Hey bro, Python data structures and algorithms would be awesome 🔥🔥

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว +4

      maybe in the future, most of my viewers wanted Java

  • @embodormo7398
    @embodormo7398 3 ปีที่แล้ว

    Thanks for video

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว

      np! Thanks for watching EMbo!

  • @Poria_q
    @Poria_q 7 หลายเดือนก่อน

    You're the best

  • @shreehari2589
    @shreehari2589 3 ปีที่แล้ว +1

    Hey bro, can you start data structures and algorithms using python please?

    • @BroCodez
      @BroCodez  3 ปีที่แล้ว

      maybe in the future, most people wanted Java

  • @collynecity3331
    @collynecity3331 ปีที่แล้ว +1

    Introduction for me😂😂😂😂
    Ohhh yeah😾🎭🎭🎭🎭

  • @mayarmosleh9484
    @mayarmosleh9484 9 หลายเดือนก่อน

    Nice