Selection sort in 3 minutes

Поділитися
Вставка
  • Опубліковано 8 січ 2025

КОМЕНТАРІ •

  • @klutchboi3266
    @klutchboi3266 3 роки тому +631

    I watched it at 2x and learned selection sort in 1min and 21 seconds.

    • @iamdeepak__
      @iamdeepak__ 11 місяців тому +14

      I understood it in the first swap itself.. In 30 seconds.

    • @M-R-Editor
      @M-R-Editor 11 місяців тому +1

      ​@@iamdeepak__😂😂

    • @4NDTRY
      @4NDTRY 11 місяців тому +1

      ​@@iamdeepak__*understood

    • @4NDTRY
      @4NDTRY 11 місяців тому +1

      *2 min 21.5 secs

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

      @@4NDTRY yeh 👍

  • @RickyCruz1301
    @RickyCruz1301 4 роки тому +545

    my prof made 90 slides in pseudo code and loop invariants that i didnt even know what was happening, watching your video it makes so much sense, thank you and keep up the great work

    • @mandevsingh9800
      @mandevsingh9800 3 роки тому +37

      Gatdamn, 90 slides. Das Mad!

    • @kamwow9469
      @kamwow9469 Рік тому +8

      Lmao loop invariants? Did you go to Cornell

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

      @@kamwow9469 bro every University brings up loop invariants or induction to prove algorithms. Professors even say "This is the only time you will ever need to formally prove an algorithm". 😂🥲

    • @lucutes2936
      @lucutes2936 Рік тому +4

      tell him to change his way of teaching or get him fired

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

      Makes me feel really blessed to have a prof like mine. Only needed to watch this video because I missed that class

  • @somedude6733
    @somedude6733 3 роки тому +69

    Here I am paying tuition to be taught this in 8 days and 3 1 hour long videos, meanwhile this video taught me this is less than 3 minutes.
    You are saving my Data structures and algorithms module.
    Thank you

  • @MaxAttaxxxxxxxxx
    @MaxAttaxxxxxxxxx 5 років тому +204

    Thank you so much for explaining this simply and effectively. The real example to follow along with is helpful and the psudocode at the end puts it back into a more studious context.

  • @laurentbajrami3688
    @laurentbajrami3688 4 роки тому +38

    Best explanation I've seen on the topic

  • @natqt93
    @natqt93 Рік тому +6

    my professor explained this in a way that made my brain scramble. lol but here I am learning it in a few minutes. thank you so much for these videos.

  • @maxresdefault8235
    @maxresdefault8235 4 роки тому +15

    Really good. Simple, quick, easy. Much better than the other youtube videos which are practically 10-30 minute lectures that explain the same thing.

  • @andreacorrales7388
    @andreacorrales7388 3 роки тому +4

    I spent a couple days trying to wrap around this... and this video helped me ALOT!!! And THANK YOU FOR THE PSEUDO CODE!

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

    Thanks for this quick, easy and unambiguous explanation of the sorting algorithm

  • @masoodsediqi1440
    @masoodsediqi1440 5 років тому +16

    Thank you so much for explaining this simply and effectively.

  • @newmb321
    @newmb321 4 місяці тому +3

    my professor kept rambling and rambling until I was just like, "do you even know how this works?" he admitted he didn't so I told him to put on Michael Sambol. later, he thanked me after class and told me that he had spent years trying to figure this one out.

  • @Mdt-24
    @Mdt-24 6 місяців тому

    Thank u for this, first time doing algorithms and data structure coding, got confused on how selection sort worked, watched this and instantly knew what to do basing my code off this.

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

      Awesome! Check the code repo if you have any doubts: github.com/msambol/dsa.

  • @How2hit
    @How2hit 5 років тому +7

    Dude. You explained very well. Simple and clear!

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

    Well I have my offline college starting in two days and i didnt pay attention to all of this but now I don't regret it.. thanks brother ♥️✌️

  • @star831
    @star831 3 роки тому +4

    Thank you so much for making such a simple to understand and concise explanation of this!!

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

    These videos are so good for refresher on algorithms before my exam.

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

      Thanks, Caleb!

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

      @@MichaelSambol 👍 Any chance you'd consider doing a video on P, NP and NP complete?

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

      @@calebkrauter4027 will add those to the list!

  •  Місяць тому

    WTF, are you a god or what? My faculty took a week to do all the sorting, and you did it in like 20 minutes.

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

    Man go and be a teacher the world needs more teachers like you

  • @instamarg5396
    @instamarg5396 6 років тому +8

    So simple. Greatly explained.

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

    Thanks!! It's just like the bubble sort, but instead of swapping the elements, we update the pointers. Neat.

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

    your videos are accurate, simple and right to the point!
    thank you for making an effort to put it out there.
    you gained a subscriber today and i'm sharing the hell out of your videos from now on!

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

      Thank you very much. More coming soon.

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

    Short, consise and easy to follow! Thank you for this!!

  • @vinsonbeduya5434
    @vinsonbeduya5434 4 роки тому +2

    Thank you. You make it sound so easy!

  • @BM-_
    @BM-_ Рік тому

    Thank you for this visual explanation, I was able to code this using your visualization!

  • @DeepakYadav-ys7dg
    @DeepakYadav-ys7dg Рік тому

    Thank you very much, just by watching your video I make a algorithm on my own

  • @meXD
    @meXD 4 роки тому +17

    For anyone looking for working JS solution:
    function selectionSort(arr) {
    const len = arr.length
    for(j=0;j

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

      cool avatar, i tried to remove this hair for 2 seconds))

  • @TeamNolex
    @TeamNolex Рік тому +2

    *The time complexities are*
    Best: O(n^2)
    Average: O(n^2)
    Worst: O(n^2)
    Storage: O(1)

  • @jsteezeful
    @jsteezeful 5 років тому +1

    Thank you very much! Python code:
    array = [2,8,5,3,9,4,1]
    def selection_sort(A):
    print(f"Starting Array: {A}
    ")
    for o_idx, o_val in enumerate(A):
    min = o_val
    print(f"Iteration #{o_idx+1}: pointer={o_val}, min={min}, array={A}")
    for i_idx, i_val in enumerate(A[o_idx+1:]):
    if i_val < min:
    old_min, min = min, i_val
    min_idx = o_idx+i_idx+1
    print(f" Comparison: {min} < {old_min}")
    else:
    print(f" Comparison: {i_val} > {min}")
    else:
    A[o_idx], A[min_idx] = min, o_val
    print(f" Swapping: {min} & {o_val}")
    print(f"{A}
    ")
    print(f"Resulting Array: {A}")

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

    What an amazing and simple explanation... Thanks a lot sir!💝

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

    Thank you, this is helping me in the exam ❤

  • @happychuckprogramming6048
    @happychuckprogramming6048 5 років тому +1

    thank you Michael. Very nice and clean explanation. Good job. Keep it up.

  • @Jeb-OGD
    @Jeb-OGD 4 роки тому

    I never thought it would be this easy

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

    Lol came back here after my prof played this and your other videos on sorting to us.

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

    bro should have a Nobel prize for teaching

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

    SUPER Simple and quick explaniation ! THANK U

  • @purleedef
    @purleedef 5 років тому +8

    I watched this up to about 45 seconds where he had minimum set to 2 and current set to 1 and thought to myself "Please don't swap them. Please don't tell me we swap" then he had the fucking had the nerve to swap them and I'm not gonna lie, it really fucked up my morning.

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

      Lmao, this comment made my day XD

  • @bleach92master
    @bleach92master 8 років тому +11

    Great vids, easy and simple for revision :) Thanks!

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

    this guy is sorting my ideas

  • @KerrKerr
    @KerrKerr 8 років тому +2

    Nicely done. I remember watching the Kruskal and Dijstra algorithms back when I had classes. Keep up!

  • @anonymoustv8604
    @anonymoustv8604 4 роки тому +3

    Thanks a lot! Understood it completely man!

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

    Great explaining. Useful for my subject Algorithm Analysis😄

  • @ronitmehta2594
    @ronitmehta2594 4 роки тому +3

    THANK YOU!! this was amazing

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

    just learned this from your video and wow this goes hard for smaller lists. looks like I'll need more than quick sort after all if my cool is to overoptimize sorting performance to have as-responsive-as-possible ui and fast builds :)

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

    Great video! Exactly what I needed. tyvm!

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

    i literally love you

  • @n.btrung
    @n.btrung 5 років тому +2

    thank you for such an useful video!

  • @random-0
    @random-0 3 роки тому

    best video on selection sort

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

    Thank u so much short and precise.

  • @jenliang5292
    @jenliang5292 5 років тому +1

    awesome, clean, and clear, thanks

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

    amazing! thank you for the clean explanation

  • @yuvaranikannan9297
    @yuvaranikannan9297 5 років тому +2

    You made it simple.♥️

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

    I did terrible on my CSA quiz, and this video wasn't there to help me when i needed. :(((

  • @kostadinvalchev1781
    @kostadinvalchev1781 4 роки тому

    Simple explanation. Thanks a lot!

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

    *Best sorting algorithm right there, no better one! Yup.*

  • @BillijeanS442
    @BillijeanS442 5 років тому

    Very nice visualisation, thanks

  • @mysticstardust1109
    @mysticstardust1109 5 років тому

    Fast and simple thank you so much

  • @VihaanKumar-o1s
    @VihaanKumar-o1s 10 місяців тому

    too good...
    it is a very nice explanation...

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

    I think I’ve got it but let me just explain it in my own words and you can tell me if I got it correct.
    so for each iteration:
    * we start out with the left-most unsorted number. (I will refer to this number as, “j” and I will refer to the number to the left of j as, “k”.) but for the first iteration, we will use 0 for the value of k.
    * We check the array from left to right looking for the smallest number that is less than j but greater than k and if we find one, we will call that number, “q”
    * if we don’t find a number that is less than j and greater than k, we mark j as sorted and j stays in its current position throughout the entire sorting process because there is nothing that needs to be moved to the left of it.
    * However, if we do find a number that is less than j and greater than k, we will swap j with q (remember when I say, “q”, I mean the number that is less than j and greater than k) and mark q as sorted and q stays in its current position because there is nothing that needs to be moved to the left of it.

  • @adityabehera3982
    @adityabehera3982 4 роки тому

    We divide the array into 2 partitions, the sorted array and non-sorted array, which we don't do in bubble sort. #IISH11CSHLIC

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

    Thanks for making this video!

  • @saeedmirzaei1
    @saeedmirzaei1 4 роки тому

    Very nice job! Thank You.

  • @tanhanvincentt.3391
    @tanhanvincentt.3391 4 роки тому

    best explanation 💕

  • @ghazi2796
    @ghazi2796 6 років тому

    Neat Presentation & Simple Explaination.
    I Like (Y)

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

    these vids are soooooooooo helpful man

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

    You know it's a big thing when it's now 3 minutes long

  • @Jacob-cm3io
    @Jacob-cm3io 5 років тому

    I love you Michael.

  • @jacksonmckay1218
    @jacksonmckay1218 2 роки тому +2

    omg u saved my life period girl thanks queen!!!!!!

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

    i love these cute little videos

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

    depending on the searching algorithm, algorithm can go to NLogN absolute worst case.. remember you are searching in a sorted list.. even if you start sorted decreasing order..

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

    Commenting took longer then understanding this. Take a slice of this quick sort

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

    After suffering the youtube..finally i got you 😂...

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

    Excellent explained

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

    These video helped me alot

  • @thechaoslp2047
    @thechaoslp2047 4 роки тому +6

    hey is the (if iMin!=j) clause really nnecessary? Wouldn't it just swap it with itself and thereby not change anything

    • @paxcaster
      @paxcaster 4 роки тому

      iirc the point of having this clause is to be more efficient
      depending on the size of the array and the complexity of the program you might be unnecessarily swapping a lot of numbers over and over, wasting time/energy

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

    yeah, the animation is wrong, the red index does not move with the blue one at the same time...

  • @SmartProgramming
    @SmartProgramming 6 років тому

    nice one sir 👍👍

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

    fantastic and simple!!!

  • @bashaier44
    @bashaier44 4 роки тому

    So smooth
    Youre the best

  • @aakashvarunraj1279
    @aakashvarunraj1279 4 роки тому +2

    Can you put a video on insertion sort?
    If so that would be great!!

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

    nice bro less time n more efficient cool keep it up!!!!

  • @fupopanda
    @fupopanda 6 років тому +26

    The choice of starting array still leaves room for confusion.

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

    perfect perfect thank you king

  • @thetechmaster6510
    @thetechmaster6510 4 роки тому

    This is proper explain, I went to other veedeo and no good

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

    I understood so quick!

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

    Sos mas grande que hay. Mastodonte

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

    WHY DID I FIND THIS RIGHT AFTER MY COMPUTER exams

  • @Tombalino
    @Tombalino 6 років тому

    Great explanation

  • @sovannseung6985
    @sovannseung6985 5 років тому

    Useful video. Thanks.

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

    I LOVE YOU!!!!
    GOD BLESSSSSSS YOUR LIFEEE

  • @riyamani8161
    @riyamani8161 4 роки тому +1

    #IISH11CSHLIC Selection sort is a swap between the minimum value and the current value after a complete loop.

  • @liujianghao1720
    @liujianghao1720 6 років тому +16

    it can be improved by add best case worst case and time complexity

    • @jstr__
      @jstr__ 5 років тому +1

      The time complexity for best case, worst case, and avg case are all O(n^2)

    • @Mark-tv1zs
      @Mark-tv1zs 5 років тому +1

      All three of those cases are O(n^2)

  • @1.Crazy_Engineer
    @1.Crazy_Engineer 2 роки тому

    Thank you very much 🌹❤

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

    you were violating the law by setting the name of the counter for the inner loop to i and for the outer loop to j

  • @FLX-vq6yu
    @FLX-vq6yu 5 місяців тому

    if j = i + 1, shouldn't the current item j of the inner loop, which indicates the blue arow in the video, starts one behind the red arow during each iteration instead of showing up together under the same number?

  • @2SourceFort
    @2SourceFort 4 роки тому

    You are awesome...thank a lot

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

    Good video but didn't explain or I didn't understand what happens when 2 or more numbers are the same

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

    can someone tell me is this another implementation of selection sort? or this is other kind of sort? note that in the code I'm not looking for "iMin" or something like that, just straight swap when I catch a smaller element
    void sort(vector & arr, int n) {
    for (int i = 0; i < n - 1; i++)
    for (int j = i + 1; j < n; j++)
    if (arr[i] > arr[j])
    swap(arr[i], arr[j]);
    }

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

    I would've failed if it weren't for your videos

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

    Thank you for the fantastic video. I use it a lt a lot in my classes, but the pseudocode is confusing. The part of the FOR LOOP that says J < n - , should this be j = n-1??

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

    If i get a question asking how many iteration it took overall