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...
    ===========================================================
  • Наука та технологія

КОМЕНТАРІ • 212

  • @BroCodez
    @BroCodez  3 роки тому +99

    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 Рік тому +3

      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 6 місяців тому

      ​@@andreamixvlog7478yeah you can get it

  • @dhoneybeekingdom7889
    @dhoneybeekingdom7889 Рік тому +16

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

  • @jaykay8426
    @jaykay8426 18 днів тому +2

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

  • @ashmikanln3110
    @ashmikanln3110 10 місяців тому +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!

  • @drpwnage23
    @drpwnage23 Рік тому +11

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

  • @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

  • @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

  • @thainguyenviet3267
    @thainguyenviet3267 3 роки тому

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

    • @BroCodez
      @BroCodez  3 роки тому

      Thanks! I will continue

  • @moum.a8130
    @moum.a8130 3 роки тому +29

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

    • @BroCodez
      @BroCodez  3 роки тому +9

      thanks for watching!

  • @user-pd9yp7ru4x
    @user-pd9yp7ru4x 3 роки тому +11

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

    • @BroCodez
      @BroCodez  3 роки тому +6

      sweet! I'm glad the videos are helping!

  • @barelycodingtoday
    @barelycodingtoday Рік тому

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

  • @aleacevedo1016
    @aleacevedo1016 Рік тому

    As always... excellent videos! Thanks!

  • @user-dx2zs9bi5j
    @user-dx2zs9bi5j 10 місяців тому

    Great Video mate!

  • @sahinyusifli9756
    @sahinyusifli9756 Рік тому

    Thank you. It was so helpful!!

  • @aliiiccyee5736
    @aliiiccyee5736 Рік тому

    I love u!!!! Thank u for making the concept so clear n understandable💝

  • @dankmemequeen9581
    @dankmemequeen9581 Рік тому

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

  • @Viva-Crusader
    @Viva-Crusader 2 роки тому

    Great explanation, thank you so much.

  • @plankalkulcompiler9468
    @plankalkulcompiler9468 Рік тому

    Very helpful video, thank you!

  • @leonardopensador
    @leonardopensador 4 місяці тому

    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.

  • @Tomteluva82
    @Tomteluva82 3 місяці тому

    very useful, thanks!

  • @T-Rex0711
    @T-Rex0711 8 місяців тому +4

    Defeat the algorithm, Bros.

  • @BN-cr3el
    @BN-cr3el 3 роки тому +2

    💯 thank you!

  • @MohammadJavadd
    @MohammadJavadd Місяць тому

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

  • @qwikz5389
    @qwikz5389 3 роки тому +1

    this helped me out thank you

    • @BroCodez
      @BroCodez  3 роки тому +1

      Thanks for watching Qwikz!

  • @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!

  • @junialdy
    @junialdy Рік тому

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

  • @bagnotneeded
    @bagnotneeded Рік тому

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

  • @sadman6852
    @sadman6852 4 місяці тому

    Thank you bro!

  • @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 ?

  • @dharmeshajudiya1709
    @dharmeshajudiya1709 Рік тому

    Good explantation, Thanks for sharing

  • @Omar-_-_
    @Omar-_-_ 2 роки тому

    Amazing, thanks alot

  • @jacklagos936
    @jacklagos936 10 місяців тому

    Many thanks!

  • @johnhansen4794
    @johnhansen4794 3 роки тому

    Clear and Concise. Thanks.

    • @BroCodez
      @BroCodez  3 роки тому

      Thanks for watching John!

  • @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 ❤

  • @jerrypolemica2704
    @jerrypolemica2704 Рік тому

    Thanks from Italy!

  • @user-xm5jw7oo5g
    @user-xm5jw7oo5g 7 місяців тому

    great man

  • @Cristian-me9id
    @Cristian-me9id 5 місяців тому

    thank you (:

  • @youcefmantas4944
    @youcefmantas4944 Рік тому

    Thanks Mate!!

  • @nikitos2442
    @nikitos2442 3 роки тому

    Like always...legendary!

  • @IsaacAwad.04
    @IsaacAwad.04 Місяць тому

    thanks man

  • @xeahmedrefat2972
    @xeahmedrefat2972 Рік тому

    Thanks from Egypt❤‍🔥

  • @andres9108
    @andres9108 2 місяці тому

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

  • @MrLoser-ks2xn
    @MrLoser-ks2xn Рік тому

    Thanks!

  • @muhammed__5
    @muhammed__5 6 місяців тому

    very well done!

  • @wolfskind9135
    @wolfskind9135 3 роки тому

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

  • @ThEHUNtErCr9
    @ThEHUNtErCr9 3 місяці тому

    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

  • @user-do3tq9gu3h
    @user-do3tq9gu3h 8 місяців тому

    thank you!

  • @CSstudent_1001
    @CSstudent_1001 9 місяців тому

    Thank you

  • @yehannk448
    @yehannk448 3 роки тому

    Bro thanks just what i was looking

    • @BroCodez
      @BroCodez  3 роки тому

      awesome! Thanks for watching Yehan!

  • @admoonhermiz1
    @admoonhermiz1 9 місяців тому

    thank you!!!

  • @Anonymationsthecoolanimator
    @Anonymationsthecoolanimator 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

  • @_4p_
    @_4p_ 10 місяців тому

    it was perfect.
    all of it

  • @Snowmanver2
    @Snowmanver2 2 роки тому +17

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

  • @matinmonshizadeh
    @matinmonshizadeh 2 роки тому

    thanks bro :D

  • @MeditateRelaxEtcetera
    @MeditateRelaxEtcetera 4 місяці тому

    You've got it sorted out.😎

  • @TITAN-sv5eg
    @TITAN-sv5eg Рік тому

    thanks for clarify this

  • @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?

  • @wallstreetbets7741
    @wallstreetbets7741 Рік тому

    Learnt thx

  • @iamfromasean705
    @iamfromasean705 3 роки тому +1

    Thank you for the algorithm!

    • @BroCodez
      @BroCodez  3 роки тому +1

      Thanks for commenting to help with the UA-cam algorithm!

    • @iamfromasean705
      @iamfromasean705 3 роки тому

      @@BroCodez Bro, can you do quick sort , please?

  • @Poria_q
    @Poria_q 5 місяців тому

    You're the best

  • @joelpose7269
    @joelpose7269 Рік тому +1

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

  • @cashionsteven5695
    @cashionsteven5695 2 роки тому

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

  • @autosuggestionasshole9208
    @autosuggestionasshole9208 3 роки тому

    the best channel on youtubeeee

  • @user-eh3zv9pv1z
    @user-eh3zv9pv1z Рік тому

    Thanks

  • @indigo_diary
    @indigo_diary 9 місяців тому

    than you!!

  • @MaRvELsNERD
    @MaRvELsNERD 5 місяців тому

    Bro is the goat 🐐

  • @mayarmosleh9484
    @mayarmosleh9484 7 місяців тому

    Nice

  • @Remolhunter97
    @Remolhunter97 3 роки тому

    Perfect 👌🏼

  • @mohamedabdirizakahmed3539
    @mohamedabdirizakahmed3539 8 місяців тому +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..

  • @LoveTaiwan678
    @LoveTaiwan678 3 роки тому

    Thank you ;)

    • @BroCodez
      @BroCodez  3 роки тому +1

      thanks for watching Yu!

  • @sakuriosky1573
    @sakuriosky1573 8 місяців тому +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 5 місяців тому

      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!

  • @JakeD21
    @JakeD21 Рік тому

    Legend.

  • @learner8005
    @learner8005 Рік тому

    New bro here loved you video brooooo🤘🤘🤘

  • @vehanhemsara9793
    @vehanhemsara9793 3 роки тому +1

    Thank You

  • @kyawsanaung2019
    @kyawsanaung2019 2 місяці тому

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

  • @gabrielcasanova7034
    @gabrielcasanova7034 2 роки тому +1

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

  • @chefskiss651
    @chefskiss651 Рік тому

    What should I do if I'm dealing with a large data set?

  • @genesiscereno5106
    @genesiscereno5106 Рік тому

    tHank you broooo

  • @Dumb4Creepy
    @Dumb4Creepy 9 місяців тому

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

  • @youssofprogrammer7546
    @youssofprogrammer7546 Рік тому

    amazing

  • @jdserrato3792
    @jdserrato3792 9 місяців тому

    I will savour this moment that does not involve recursion

  • @sakiszintros7782
    @sakiszintros7782 4 місяці тому

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

  • @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!

  • @MohitRaj-1712
    @MohitRaj-1712 3 роки тому

    you deserve more subscribers.

  • @embodormo7398
    @embodormo7398 3 роки тому

    Thanks for video

    • @BroCodez
      @BroCodez  3 роки тому

      np! Thanks for watching EMbo!

  • @official_ardi4840
    @official_ardi4840 2 роки тому

    Yo bro i understand the code but something that i missing is
    How can we scan from the beginning again after we scanned all the array? I still didnt get it

  • @jessicabull3918
    @jessicabull3918 3 місяці тому

    is each lap the same as an iteration?

  • @inspired12121
    @inspired12121 11 місяців тому

    hey you, thank you

  • @tronganhnguyenthanh1157
    @tronganhnguyenthanh1157 7 місяців тому

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

  • @julianrobinson2848
    @julianrobinson2848 10 місяців тому

    Why do we need the temp variable?

  • @meetprotrash3178
    @meetprotrash3178 3 роки тому +1

    I love you bro thanks 😘💙❤️😘

  • @wolanus
    @wolanus 3 роки тому

    Great video

  • @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

  • @geografixxxx
    @geografixxxx 11 місяців тому

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

  • @envektro2519
    @envektro2519 3 роки тому +2

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

  • @majdkinani587
    @majdkinani587 5 місяців тому

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

  • @NormaNsNs
    @NormaNsNs 10 місяців тому

    what does it mean j

  • @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

  • @aleksandarduncevic9548
    @aleksandarduncevic9548 8 місяців тому +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 7 місяців тому

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