Learn Selection Sort in 8 minutes 🔦

Поделиться
HTML-код
  • Опубликовано: 19 окт 2024
  • data structures and algorithms selection sort algorithm
    #selection #sort #algorithm
    // selection sort = search through an array and keep track of the minimum value during
    // each iteration. At the end of each iteration, we swap variables.
    // Quadratic time O(n^2)
    // small data set = okay
    // large data set = BAD
    music credits 🎼 :
    ===========================================================
    Block Party - Bad Snacks
    link: • bad snacks: RUclips Au...
    ===========================================================

Комментарии • 182

  • @BroCodez
    @BroCodez  3 года назад +94

    public class Main{

    // selection sort = search through an array and keep track of the minimum value during
    // each iteration. At the end of each iteration, we swap values.

    // Quadratic time O(n^2)
    // small data set = okay
    // large data set = BAD

    public static void main(String[] args) {

    int array[] = {8, 7, 9, 2, 3, 1, 5, 4, 6};

    selectionSort(array);

    for(int i : array) {
    System.out.print(i);
    }
    }
    private static void selectionSort(int[] array) {

    for(int i = 0; i < array.length - 1; i++) {
    int min = i;
    for(int j = i + 1; j < array.length; j++) {
    if(array[min] > array[j]) {
    min = j;
    }
    }

    int temp = array[i];
    array[i] = array[min];
    array[min] = temp;
    }

    }
    }

    • @aditya_asundi
      @aditya_asundi 3 года назад +3

      u forgot to pin it =)

    • @joyceasante8292
      @joyceasante8292 Год назад +2

      Practicing...
      Ascending Order
      public class Main
      {
      public static void main(String[] args) {
      int array[] = {8,3,4,1,0,5,2,6,7};
      selectionSort(array);

      for(int i : array){
      System.out.print(i);
      }
      }
      public static void selectionSort(int[]array){
      for(int i = 0; i < array.length - 1; i++){
      int min = i;
      for(int j = i + 1; j array[j]){
      min = j;
      }
      }
      int temp = array[i];
      array[i] = array[min];
      array[min] = temp;
      }
      }
      }
      ********************
      Descending order
      public class Main
      {
      public static void main(String[] args) {
      int array[] = {8,3,4,1,0,5,2,6,7};
      selectionSort(array);

      for(int i : array){
      System.out.print(i);
      }
      }
      public static void selectionSort(int[]array){
      for(int i = 0; i < array.length - 1; i++){
      int min = i;
      for(int j = i + 1; j

    • @giorgiogiorato
      @giorgiogiorato Год назад +2

      4:35

  • @faizanhamza4717
    @faizanhamza4717 9 месяцев назад +61

    Half of my tension wipes away when he says sit back and relax

  • @mykytakaida6663
    @mykytakaida6663 3 года назад +136

    Man, I wish you will become the greatest programming RUclipsr in a year

    • @Remolhunter97
      @Remolhunter97 3 года назад +21

      He already is, he just has not enough visibility !

    • @solens4810
      @solens4810 3 года назад +6

      Me too, I love himmmm

    • @BroCodez
      @BroCodez  3 года назад +39

      Thanks guys! You are all the best! ❤️

    • @mrnotrobot
      @mrnotrobot Год назад +3

      @@BroCodez Thanks sir! For all the work!

    • @ritikbisen798
      @ritikbisen798 Год назад +1

      May your dreams come true bro 😊😊

  • @adi_is_back
    @adi_is_back Год назад +47

    Studying as usual one day before a test and I was so confused on selection sort, but this video has helped me a lot! Thanks and keep up the great work!

  • @hridayinfovlogs
    @hridayinfovlogs Год назад +14

    Bro,,
    Programming tortures me due to the bad teachers I have
    But u, r the best programmer and teacher
    U help me learn programming like it is just a childhood game.
    Thanks a lot !,

    • @MarcusHCrawford
      @MarcusHCrawford Месяц назад

      I know how you feel! Hang in there. Thankfully, we have so many great resources online to ease the burden of poor instruction. Hope everything is going well.

  • @j.m8480
    @j.m8480 2 года назад +6

    I'm studying to become a software engineer atm... and I keep returning here time and time again for insanely good and fast introductions to pretty much ALL the concepts 🤣🤣 Bro is the master. Thank you!

  • @MinecraftTestSquad
    @MinecraftTestSquad 3 года назад +12

    I'm just going to leave this comment on your most recent video for the best chance of you seeing it.
    You are insane. I'm going through your Python full course video atm and I'm about 3-4 hours in, and I just noticed that you have full course/crash course videos for several different programming languages and then also HTML/CSS on top of that.
    That's amazing. I might even poke through your Java course just to see what new things I'll learn even though I already know a pretty good bit about Java.
    I'll probably watch your Java swing videos since I don't know a whole bunch about swing.
    This channel deserves *MUCH* more attention.

    • @BroCodez
      @BroCodez  3 года назад +6

      Thank you MinecraftTestSquad!
      Yes I am a little insane 🤪

  • @halloheinz
    @halloheinz 7 месяцев назад +10

    A man uses paint to explain in 8 minutes an algorithm and achieves more than a professor at the university in 6 Months. Well done and thanks.

  • @DetCoAnimeFan
    @DetCoAnimeFan 3 года назад +20

    I have seen that many people love Bubble sort because it is easier to learn however I think Selection sort is better as it seems simpler to me other than being faster than Bubble sort.

    • @supernovic99
      @supernovic99 Год назад +1

      Oh my god. I completely agree. I never understood why people consider bubble sort to be easy. For me, selection and insertion sort are much easier.

    • @andreuz_2998
      @andreuz_2998 9 месяцев назад

      insertion is even better , it just make the change everytime it needs to , after studying both for hours , and practice many of examples , the conclusion was that insertion will always be better than selection.

    • @okeuwechue9238
      @okeuwechue9238 7 месяцев назад

      Bubble is extremely inefficient. Shouldn't be used in RL

  • @diegoortega2374
    @diegoortega2374 Год назад +1

    Thanks brother, I really liked your explanation and the effort you made to graphically show the algorithm. Cheers!

  • @LeoLeo-us5rs
    @LeoLeo-us5rs 3 года назад +2

    Best selection sort explanation on RUclips

  • @nidarr4878
    @nidarr4878 9 месяцев назад +1

    This was really helpfull. It made selection sort a piece of cake. Thanks a lot. Outstanding video

  • @nareshmangalpalli1480
    @nareshmangalpalli1480 Год назад +1

    best Explanation + nice examples = This Video

  • @supernovic99
    @supernovic99 Год назад +3

    Thank you so much for this video bro!!! It was really helpful

  • @kenanturan824
    @kenanturan824 3 года назад +1

    Hi bro. I just discovered this youtube channel so I'm happy. I learn English about for 1 years and I'll watch your videos

    • @BroCodez
      @BroCodez  3 года назад +1

      Thanks Kenan! I believe there's translation available if that helps

  • @manikantaanumalla4104
    @manikantaanumalla4104 Год назад

    Super visual and incredibly interesting way of learning of DS and algorithms. Bro code rocks!!!

  • @ravishyadav7964
    @ravishyadav7964 3 года назад +4

    Just amazing how many videos you are going to upload in this data structure and algo series I want to learn a lot from you

    • @BroCodez
      @BroCodez  3 года назад +1

      I'm not quite sure yet. I'm planning 20+ topics for this series, there's a lot to cover

    • @ravishyadav7964
      @ravishyadav7964 3 года назад +1

      @@BroCodez yeah you can make it as long as you want because it is quite important series we will watch all of them

  • @necothegrim3419
    @necothegrim3419 11 месяцев назад +3

    Everybody gangsta till your teacher gives sorting algorithm assignment on *linked lists with multiple variables* .

  • @juanbelmonth1594
    @juanbelmonth1594 2 месяца назад

    Bro, you use very accurate analogies. They say that when you master a subject, you can explain it to a 6 year old child or a dumb adult (I'm the latter). Your channel is worth pure gold

  • @okeuwechue9238
    @okeuwechue9238 7 месяцев назад

    Thnx for the vid. Very clear explanation.
    However, it implies that the algo is caching the VALUE of the array elements when searching for the min element. That's not the case. What the algo caches is simply the INDEX of the value, so @2:02 it should cache the index value "3", not the data value "2", then use that index value to locate the corresponding data and perform the swap.

  • @patrickmayer9218
    @patrickmayer9218 Год назад

    It's basically the naive way of sorting, but slightly smarter because the array gets smaller each iteration.
    Thanks for the video!

  • @aminmoafi5148
    @aminmoafi5148 Год назад +2

    Lifesaver! Thank you!

  • @raihanrony1810
    @raihanrony1810 3 года назад +2

    Thanks for the visual presentation.
    I figured out how tk do it on my own thanks to the slide.

    • @BroCodez
      @BroCodez  3 года назад +3

      Thanks for watching Raihan!

  • @yaverjavid
    @yaverjavid 3 года назад +1

    I created this without checking any algorithm:
    array = input("Enter Array *[max element: (10)^18]
    (Numbers Separated By Space):").split(" ")
    a = len(array)
    sorted_array = []
    while a > 0:
    smallest = 1000000000000000000
    for i in array :
    if(int(i)

  • @LizyAd
    @LizyAd 3 дня назад

    Thanks so much for this! You are amazing.

  • @sushruthkumaresan6087
    @sushruthkumaresan6087 10 месяцев назад

    Bro finished a 30min lesson in 8 minutes and looks like its more clearer than ever

  • @coder4937
    @coder4937 3 года назад

    you are very good person who is teaching free of cost i'm glad to found this channel and n amazing person ^^

  • @qrinni4042
    @qrinni4042 9 месяцев назад

    Bro, you made this so easy to understand. Tysm

  • @BackTasty
    @BackTasty 3 года назад +2

    great job man, keep it up

    • @BroCodez
      @BroCodez  3 года назад

      Thanks Maurizio! I'll keep it up!

  • @sylvanfranklin6904
    @sylvanfranklin6904 3 года назад +1

    Bro, epic graphic design on the thumbnail and explanation!

    • @BroCodez
      @BroCodez  3 года назад

      Thanks Sylvan! I've been trying to improve the thumbnails. I'm no graphic designer tho :/

    • @sylvanfranklin6904
      @sylvanfranklin6904 3 года назад

      @@BroCodez They look great

  • @marckhycs319
    @marckhycs319 3 года назад +2

    Just got busy studying PHP for final project, here I am again studying Java😁 Big thanks😍

    • @BroCodez
      @BroCodez  3 года назад +1

      You're welcome Marckhycs! Thanks for watching!

  • @ShimmerBodyCream
    @ShimmerBodyCream 8 месяцев назад

    This is a fantastic explanation, thank you.

  • @JorgeFerreira-dp9og
    @JorgeFerreira-dp9og Год назад

    Best explanation ever! Thank you

  • @youssofprogrammer7546
    @youssofprogrammer7546 2 года назад

    you are amazing you are the only youtuber in whole youtube let me know this topic very very thanks

  • @AnuragKumar-ce8hl
    @AnuragKumar-ce8hl 3 года назад +1

    wow , such a nice & simple explanation, Thank you so much Bro Code

    • @BroCodez
      @BroCodez  3 года назад

      You're welcome Anurag! Thanks for watching!

  • @thestars8300
    @thestars8300 Год назад

    Thank you so much I have a data structure exam tomorrow I hope I will get full marks

  • @ShadowKnightdxrk
    @ShadowKnightdxrk 9 месяцев назад +1

    I m lucky to find his
    Btw im a new subascriba

  • @JatBadmos
    @JatBadmos Год назад

    love your videos bro thanks for the help 😃

  • @raykos4257
    @raykos4257 Год назад

    Woah. That was a really good video.

  • @kindness3110
    @kindness3110 2 года назад +1

    Hey Bro! Can i ask a question? why in inner loop j = i + 1, why not just j = 1? I'm still trying to getting a hang of this

    • @samson-zq7gc
      @samson-zq7gc 2 года назад

      I think because you are not sorting the very last element in the array. Because once the first four items are sorted, you don't have to iterate through the last element in the array. There is no where else for it to go.

  • @SpeaksYourWord
    @SpeaksYourWord Год назад

    Wouldn't it be simpler if we just applied the bubble sort logic and start iterating from the end and keep swapping the smaller value to the front?

  • @FarizAzim
    @FarizAzim Год назад +1

    thanks bro
    saved my butt in class

  • @_max_7770
    @_max_7770 3 года назад +2

    hey @Bro Code may I ask you what shoud I learn in free time at hight school? I mean for the future job what will be the best programming language for example in the US.
    PS. I really appreciate you work at yt and I hope you will be very lucky in the future:)

    • @BroCodez
      @BroCodez  3 года назад +2

      Thanks for the support max!
      It really varies on what U.S. employers want so it's difficult to give a definite answer. There's a lot of overlap between languages. If you know one, a lot of what you learned transfers to another.

  • @TonyMalik7
    @TonyMalik7 3 года назад

    thankyou so much for
    teach me
    sir your all videos are the best video
    i was see many video of teach coding
    but your teaching is best in world of youtube
    thank you so much

    • @BroCodez
      @BroCodez  3 года назад

      Thank you for the kind words Tony!
      I'm happy to help!

    • @TonyMalik7
      @TonyMalik7 3 года назад

      @@BroCodez welcome sir and
      thank you for reply

  • @iamfromasean705
    @iamfromasean705 3 года назад

    Thanks for the tutorial!

  • @cynthiaalvarez1346
    @cynthiaalvarez1346 Год назад

    bro code, your background music is great study music. Do you have a playlist?

  • @kalyankumar8629
    @kalyankumar8629 2 года назад

    "bro code"ur doing really great job bro!

  • @Smile-ih5xf
    @Smile-ih5xf Год назад +2

    Have the feeling he likes carrying nines around 😂

  • @Im_pain10
    @Im_pain10 23 дня назад

    U earned another subscriber

  • @AmNotLegend
    @AmNotLegend Год назад

    time complexity o[n2], space complexity o[1], it seems the same as bubble sorting

  • @KashifKhan-tq1um
    @KashifKhan-tq1um 3 года назад +1

    You are great Sir.

  • @vishalratna2703
    @vishalratna2703 3 года назад

    Congrats for 100k

  • @piyushbarve2618
    @piyushbarve2618 2 года назад +1

    Hello, Bro. I know this course has completed but can you please add Dynamic Programming in it?

  • @lellal5354
    @lellal5354 Год назад +2

    holy crap its a two
    that quote killed me hahahaha

  • @Rockyzach88
    @Rockyzach88 Год назад

    I guess if you knew there was no repeating numbers and if the new min is 1 above it, then you don't need to search the rest of the array.

  • @eueudruadh2268
    @eueudruadh2268 3 года назад

    Thanks bro, i really appreciate it

    • @BroCodez
      @BroCodez  3 года назад

      You're welcome! Thanks for watching Eueud!

  • @plasmafox2568
    @plasmafox2568 Год назад

    Thank you bro!

  • @abdullahalhomedna836
    @abdullahalhomedna836 8 месяцев назад

    Well said.

  • @petrone1821
    @petrone1821 3 года назад

    Bro what do you think of flutter? Are we going to get any guides on it down day?

    • @BroCodez
      @BroCodez  3 года назад

      maybe! I'll likely have you all vote on future video topics once I finish JavaScript and the C-family langauges

  • @amanthakur6913
    @amanthakur6913 3 года назад

    Amazing Explanation Bro

    • @BroCodez
      @BroCodez  3 года назад

      Thank you Aman! I'm happy to help

  • @loisarcangeles3954
    @loisarcangeles3954 2 года назад

    Great video! but may I ask what was the point of the code
    temp=num[i];
    num[i]=num[j];
    num[j]=temp;

    • @vijayanks1714
      @vijayanks1714 2 года назад

      int a = 1; int b = 10;
      now u swap the two value u need one extra variable to store it temp so declare
      int temp;
      execution temp = b; //temp store 10
      b=a; //now b store 1
      a=temp; // in the 2nd step b value is change so need a extra variable to store the b variable before the 2nd step, that's the logic behind that

    • @LynnyrdRavage
      @LynnyrdRavage Год назад

      @@vijayanks1714 Why is outer loop arraylength - 1? Instead of just being arraylength?

  • @marcosangelmedina5845
    @marcosangelmedina5845 Год назад

    thx bro, love you

  • @jrdatutorial9862
    @jrdatutorial9862 3 года назад

    The best explanation

    • @BroCodez
      @BroCodez  3 года назад +1

      Thank you jrda!

  • @nonameiskickass1319
    @nonameiskickass1319 2 года назад

    Bro is really cool 🚀🚀🚀

  • @MrLoser-ks2xn
    @MrLoser-ks2xn Год назад

    Thanks!

  • @jyotirmoydasdeep6568
    @jyotirmoydasdeep6568 Год назад

    You are the best

  • @CSstudent_1001
    @CSstudent_1001 11 месяцев назад

    Great 🌸🌸🌸

  • @youngo_music8089
    @youngo_music8089 2 года назад +1

    why did you use length-1 in the nested loop.

  • @vamsitatapudi9376
    @vamsitatapudi9376 10 месяцев назад

    Very good video! Friendly suggestions: It will be helpful if you can place the temp variable box further away from the min variable ... also, please explain what "swap using temp" means at the start of the video. This will help beginners (like my kiddo).

  • @muhammedemad1155
    @muhammedemad1155 2 года назад

    Thank you sir

  • @mikhailsandigan1424
    @mikhailsandigan1424 3 года назад

    What software are you using for your explanation?

    • @BroCodez
      @BroCodez  3 года назад +1

      Paint.net
      I'm not skilled with animations, but I'm decent with my photoshop skillz

    • @mikhailsandigan1424
      @mikhailsandigan1424 3 года назад

      @@BroCodez thank you bro, you are an inspiration!

  • @sungazing59
    @sungazing59 5 месяцев назад

    Thank you bro

  • @anonimanonim1223
    @anonimanonim1223 2 года назад

    best videos

  • @tbs-founder
    @tbs-founder Год назад

    just the best

  • @yon1623
    @yon1623 Год назад

    int min = 1 i; on line 25. i goes from 0 to length of array-1 . how does that help?

  • @wahidom
    @wahidom 5 месяцев назад

    thanks king

  • @w3jd4n
    @w3jd4n Год назад

    i don't even need an explanation atp i watch your videosjust for fun after studying

    • @LynnyrdRavage
      @LynnyrdRavage Год назад

      Why is it that at 7:10 (line 25) he defined int min = i? Why could it not be array[i] since we are focused on the element and it is the same position regardless? Also, could you explain to me the lines of code that go from line 32 to line 34? Thank you in advance.

    • @w3jd4n
      @w3jd4n Год назад

      ​@@LynnyrdRavage we declare the index only so it's easy to work with indexes when we want to traverse through the array

    • @w3jd4n
      @w3jd4n Год назад

      @@LynnyrdRavage we have 9 elements, outer for loop compares the first 8 elements with the inner loop/last 8 elements. we compare i with j and if i is bigger than j, we swap i with j using the help of the two variables, min & temp

    • @w3jd4n
      @w3jd4n Год назад

      @@LynnyrdRavage btw we use min variable so we don't lose the reference of i if you're wondering why not just directly use i

  • @saisaketh23
    @saisaketh23 3 года назад

    Hey Bro Code love ur videos

    • @BroCodez
      @BroCodez  3 года назад +1

      Thank you Sai!

  • @nguyenxuanthienphu3402
    @nguyenxuanthienphu3402 3 года назад

    can you do networking?

  • @heynermarquez6652
    @heynermarquez6652 Год назад

    Great
    S

  • @hasanaalbaker1115
    @hasanaalbaker1115 2 года назад

    thanks brother

  • @buraktreaty4720
    @buraktreaty4720 11 месяцев назад

    Let bro cook🔥🔥🔥🔥🔥

  • @hridayinfovlogs
    @hridayinfovlogs Год назад +1

    Bro,
    What will happen if the array elements are repeated..

  • @hannibalbianchi1466
    @hannibalbianchi1466 3 года назад

    👍👍👍

  • @navjotsingh2457
    @navjotsingh2457 2 года назад

    ty

  • @piotrp4102
    @piotrp4102 8 месяцев назад

    Thanks

  • @eugenezuev7349
    @eugenezuev7349 Месяц назад

    sweet

  • @Ben_in_4k
    @Ben_in_4k Год назад

    thanks bro

  • @scarlett9921
    @scarlett9921 7 месяцев назад

    谢谢你

  • @nevilleodhiambo1370
    @nevilleodhiambo1370 Год назад

    how are you printing the result am running the same code as you but it just print the first unsorted array...please help

  • @vishalratna2703
    @vishalratna2703 3 года назад

    Pls make a node js tutorial

  • @youssofprogrammer7546
    @youssofprogrammer7546 2 года назад

    I feel that this is the weirdest algorithm in the programming world i feel that it is too hard

  • @aar7790
    @aar7790 3 года назад

    thank u bro

    • @BroCodez
      @BroCodez  3 года назад

      Thanks for watching AAR!

  • @allofmystuffs
    @allofmystuffs 8 месяцев назад

    is it better than Bubble sort.?

  • @harshalpatel3774
    @harshalpatel3774 2 года назад +1

    comic sans intro

  • @chal7z
    @chal7z 5 месяцев назад

    tyyy

  • @GrittyMaholmes
    @GrittyMaholmes 3 года назад

    what are your c specs

  • @LynnyrdRavage
    @LynnyrdRavage Год назад

    Why is it that at 7:10 (line 25) you defined int min = i? Why could it not be array[i] since we are focused on the element and it is the same position regardless? Also, could anyone explain to me the lines of code that go from line 32 to line 34? Thank you in advance.

    • @ToxicPirate2
      @ToxicPirate2 24 дня назад

      It can work both ways and those lines are for swapping the two elements. Temp is used as a temporary variable for seapping

  • @yon1623
    @yon1623 Год назад

    I dont understand the code. but atlist i have the code for the homework.

  • @VictoriaLaRocque
    @VictoriaLaRocque Год назад

    nice voice :)