Selection sort in 3 minutes

  Рет қаралды 1,101,785

Michael Sambol

Michael Sambol

Күн бұрын

Пікірлер: 225
@klutchboi3266
@klutchboi3266 3 жыл бұрын
I watched it at 2x and learned selection sort in 1min and 21 seconds.
@iamdeepak__
@iamdeepak__ 9 ай бұрын
I understood it in the first swap itself.. In 30 seconds.
@M-R-Editor
@M-R-Editor 9 ай бұрын
​@@iamdeepak__😂😂
@4NDTRY
@4NDTRY 8 ай бұрын
​@@iamdeepak__*understood
@4NDTRY
@4NDTRY 8 ай бұрын
*2 min 21.5 secs
@iamdeepak__
@iamdeepak__ 8 ай бұрын
@@4NDTRY yeh 👍
@RickyCruz1301
@RickyCruz1301 3 жыл бұрын
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 2 жыл бұрын
Gatdamn, 90 slides. Das Mad!
@kamwow9469
@kamwow9469 Жыл бұрын
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 Жыл бұрын
tell him to change his way of teaching or get him fired
@anniemannie6
@anniemannie6 Жыл бұрын
Makes me feel really blessed to have a prof like mine. Only needed to watch this video because I missed that class
@MaxAttaxxxxxxxxx
@MaxAttaxxxxxxxxx 5 жыл бұрын
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.
@somedude6733
@somedude6733 3 жыл бұрын
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
@laurentbajrami3688
@laurentbajrami3688 4 жыл бұрын
Best explanation I've seen on the topic
@natqt93
@natqt93 10 ай бұрын
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 жыл бұрын
Really good. Simple, quick, easy. Much better than the other youtube videos which are practically 10-30 minute lectures that explain the same thing.
@Nella94
@Nella94 Жыл бұрын
Thanks for this quick, easy and unambiguous explanation of the sorting algorithm
@masoodsediqi1440
@masoodsediqi1440 4 жыл бұрын
Thank you so much for explaining this simply and effectively.
@Mdt-24
@Mdt-24 3 ай бұрын
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 3 ай бұрын
Awesome! Check the code repo if you have any doubts: github.com/msambol/dsa.
@pushaanbangera6030
@pushaanbangera6030 2 жыл бұрын
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 ♥️✌️
@andreacorrales7388
@andreacorrales7388 3 жыл бұрын
I spent a couple days trying to wrap around this... and this video helped me ALOT!!! And THANK YOU FOR THE PSEUDO CODE!
@calebkrauter4027
@calebkrauter4027 Жыл бұрын
These videos are so good for refresher on algorithms before my exam.
@MichaelSambol
@MichaelSambol Жыл бұрын
Thanks, Caleb!
@calebkrauter4027
@calebkrauter4027 Жыл бұрын
@@MichaelSambol 👍 Any chance you'd consider doing a video on P, NP and NP complete?
@MichaelSambol
@MichaelSambol Жыл бұрын
@@calebkrauter4027 will add those to the list!
@star831
@star831 2 жыл бұрын
Thank you so much for making such a simple to understand and concise explanation of this!!
@How2hit
@How2hit 5 жыл бұрын
Dude. You explained very well. Simple and clear!
@meXD
@meXD 3 жыл бұрын
For anyone looking for working JS solution: function selectionSort(arr) { const len = arr.length for(j=0;j
@otto_000
@otto_000 2 жыл бұрын
cool avatar, i tried to remove this hair for 2 seconds))
@aadil4236
@aadil4236 Жыл бұрын
Thanks!! It's just like the bubble sort, but instead of swapping the elements, we update the pointers. Neat.
@newmb321
@newmb321 2 ай бұрын
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.
@quaking2993
@quaking2993 3 жыл бұрын
Man go and be a teacher the world needs more teachers like you
@jsteezeful
@jsteezeful 5 жыл бұрын
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}")
@stevenlomon
@stevenlomon 10 ай бұрын
Short, consise and easy to follow! Thank you for this!!
@TeamNolex
@TeamNolex Жыл бұрын
*The time complexities are* Best: O(n^2) Average: O(n^2) Worst: O(n^2) Storage: O(1)
@XaxtonRevolution2
@XaxtonRevolution2 2 жыл бұрын
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.
@DeepakYadav-ys7dg
@DeepakYadav-ys7dg 9 ай бұрын
Thank you very much, just by watching your video I make a algorithm on my own
@muhammadrangga6922
@muhammadrangga6922 Ай бұрын
Thank you, this is helping me in the exam ❤
@BM-_
@BM-_ Жыл бұрын
Thank you for this visual explanation, I was able to code this using your visualization!
@instamarg5396
@instamarg5396 6 жыл бұрын
So simple. Greatly explained.
@vinsonbeduya5434
@vinsonbeduya5434 4 жыл бұрын
Thank you. You make it sound so easy!
@purleedef
@purleedef 4 жыл бұрын
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
@thatmg
@thatmg 2 жыл бұрын
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.
@jimsun2528
@jimsun2528 27 күн бұрын
bro should have a Nobel prize for teaching
@Jeb-OGD
@Jeb-OGD 4 жыл бұрын
I never thought it would be this easy
@shukiboom3974
@shukiboom3974 2 жыл бұрын
SUPER Simple and quick explaniation ! THANK U
@thechaoslp2047
@thechaoslp2047 4 жыл бұрын
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
@muhammadshahzebsulemani4365
@muhammadshahzebsulemani4365 2 жыл бұрын
What an amazing and simple explanation... Thanks a lot sir!💝
@Burnlit1337
@Burnlit1337 2 жыл бұрын
Lol came back here after my prof played this and your other videos on sorting to us.
@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 :)
@anonymoustv8604
@anonymoustv8604 4 жыл бұрын
Thanks a lot! Understood it completely man!
@willower888
@willower888 2 жыл бұрын
i literally love you
@eunicefoo4499
@eunicefoo4499 2 жыл бұрын
Great explaining. Useful for my subject Algorithm Analysis😄
@tylerdurden4169
@tylerdurden4169 3 жыл бұрын
Thank u so much short and precise.
@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
@random-0
@random-0 3 жыл бұрын
best video on selection sort
@ronitmehta2594
@ronitmehta2594 4 жыл бұрын
THANK YOU!! this was amazing
@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??
@mourabitiy
@mourabitiy 2 жыл бұрын
this guy is sorting my ideas
@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..
@rahimeinollahi1
@rahimeinollahi1 2 жыл бұрын
Excellent explained
@KerrKerr
@KerrKerr 8 жыл бұрын
Nicely done. I remember watching the Kruskal and Dijstra algorithms back when I had classes. Keep up!
@astridjorgensen7971
@astridjorgensen7971 8 күн бұрын
perfect perfect thank you king
@happychuckprogramming6048
@happychuckprogramming6048 5 жыл бұрын
thank you Michael. Very nice and clean explanation. Good job. Keep it up.
@BillijeanS442
@BillijeanS442 4 жыл бұрын
Very nice visualisation, thanks
@Nurlanbai
@Nurlanbai 2 жыл бұрын
Great video! Exactly what I needed. tyvm!
@fupopanda
@fupopanda 5 жыл бұрын
The choice of starting array still leaves room for confusion.
@bleach92master
@bleach92master 8 жыл бұрын
Great vids, easy and simple for revision :) Thanks!
@n.btrung
@n.btrung 5 жыл бұрын
thank you for such an useful video!
@Garrison86
@Garrison86 2 жыл бұрын
amazing! thank you for the clean explanation
@kostadinvalchev1781
@kostadinvalchev1781 3 жыл бұрын
Simple explanation. Thanks a lot!
@jenliang5292
@jenliang5292 5 жыл бұрын
awesome, clean, and clear, thanks
@aakashvarunraj1279
@aakashvarunraj1279 3 жыл бұрын
Can you put a video on insertion sort? If so that would be great!!
@FLX-vq6yu
@FLX-vq6yu 3 ай бұрын
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?
@VihaanKumar-o1s
@VihaanKumar-o1s 7 ай бұрын
too good... it is a very nice explanation...
@noapoleon_
@noapoleon_ Жыл бұрын
*Best sorting algorithm right there, no better one! Yup.*
@namankeshari7332
@namankeshari7332 Жыл бұрын
Thanks for making this video!
@kienluu2910
@kienluu2910 2 ай бұрын
thank you very much!
@obesecat69420
@obesecat69420 Жыл бұрын
I did terrible on my CSA quiz, and this video wasn't there to help me when i needed. :(((
@riddhibondre7193
@riddhibondre7193 2 ай бұрын
These video helped me alot
@mysticstardust1109
@mysticstardust1109 5 жыл бұрын
Fast and simple thank you so much
@DJayDiamond
@DJayDiamond 4 жыл бұрын
Hmmm...I'm getting whiffs of insertion sort here. Like selection sort we always look for the minimum and then swap. Insertion sort we ask is this the smallest we've seen yet then slot it into place. Similar ideas
@saeedmirzaei1
@saeedmirzaei1 4 жыл бұрын
Very nice job! Thank You.
@joie1141
@joie1141 2 жыл бұрын
Thank you very much 🌹❤
@raheemtherager9119
@raheemtherager9119 2 жыл бұрын
fantastic and simple!!!
@skylinefx049
@skylinefx049 2 жыл бұрын
yeah, the animation is wrong, the red index does not move with the blue one at the same time...
@der4n
@der4n 10 ай бұрын
i love these cute little videos
@Ralvy
@Ralvy 3 жыл бұрын
If i get a question asking how many iteration it took overall
@liujianghao1720
@liujianghao1720 6 жыл бұрын
it can be improved by add best case worst case and time complexity
@jstr__
@jstr__ 5 жыл бұрын
The time complexity for best case, worst case, and avg case are all O(n^2)
@Mark-tv1zs
@Mark-tv1zs 5 жыл бұрын
All three of those cases are O(n^2)
@yuvaranikannan9297
@yuvaranikannan9297 5 жыл бұрын
You made it simple.♥️
@tritish3191
@tritish3191 3 жыл бұрын
I understood so quick!
@monjasonsteng7861
@monjasonsteng7861 Ай бұрын
Thank you!
@rhidlor8577
@rhidlor8577 4 жыл бұрын
Would a recursive selection sort be less efficient than a nested loop selection sort?
@typingcat
@typingcat Жыл бұрын
So, the complexity is the same as bubble sort. Then, why do we need both? Is it any better than bubble sort in some specific applications?
@plutomessi21
@plutomessi21 Жыл бұрын
bubble sort is stable whereas this is unstable
@typingcat
@typingcat Жыл бұрын
@@plutomessi21 Isn't stable algorithm always better than unstable one, with all other conditions the same? I once needed a stable sort algorithm when I created a GUI that showed a sorted list of values that got constantly updated. But I don't remember any time I specifically needed an unstable algorithm.
@plutomessi21
@plutomessi21 Жыл бұрын
@typingcat yes yes stable algo is always better, selection sort is just a technique which is taught in the universities but used very less frequently in the real world😊
@nberz692
@nberz692 3 жыл бұрын
You know it's a big thing when it's now 3 minutes long
@sovannseung6985
@sovannseung6985 5 жыл бұрын
Useful video. Thanks.
@erenjohn12345
@erenjohn12345 3 жыл бұрын
Thank you so much
@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]); }
@StoryHub0079
@StoryHub0079 Жыл бұрын
Yes
@Sibearian_
@Sibearian_ 3 жыл бұрын
Thank you ❤❤❤❤
@tanhanvincentt.3391
@tanhanvincentt.3391 3 жыл бұрын
best explanation 💕
@ashhadsiddiqui3815
@ashhadsiddiqui3815 Жыл бұрын
After suffering the youtube..finally i got you 😂...
@nayanachegde6151
@nayanachegde6151 5 ай бұрын
Thank you!!
@2SourceFort
@2SourceFort 4 жыл бұрын
You are awesome...thank a lot
@frozen_here2455
@frozen_here2455 9 ай бұрын
WHY DID I FIND THIS RIGHT AFTER MY COMPUTER exams
@MichaelSambol
@MichaelSambol 9 ай бұрын
😞
@Tombalino
@Tombalino 6 жыл бұрын
Great explanation
@limitess9539
@limitess9539 Жыл бұрын
I don't understand why you put n-1 in the first for, it doesn't work for me. Here's my example of selection sort: #include int main() { int i,j,tempor,array[]={5,9,3,14,11}; printf("array before sorting: "); for(i=0;i!=5;i++) printf("array[%d] holds value %d ",i,array[i]); for(i=0;i!=5;i++) { for(j=i+1;j!=5;j++) { if(array[j]
@ironmonkey1990
@ironmonkey1990 7 ай бұрын
thank you!
@SmartProgramming
@SmartProgramming 6 жыл бұрын
nice one sir 👍👍
@bashaier44
@bashaier44 3 жыл бұрын
So smooth Youre the best
@riyamani8161
@riyamani8161 4 жыл бұрын
#IISH11CSHLIC Selection sort is a swap between the minimum value and the current value after a complete loop.
@nabamajeed
@nabamajeed 2 жыл бұрын
these vids are soooooooooo helpful man
@W4leed.
@W4leed. 5 жыл бұрын
Can you Please do a Video a video about all the other Sorting methods too? Like Bubble Sort, Insertion sort and Quick Sort?
@alphabandajr3960
@alphabandajr3960 5 жыл бұрын
Yeah I agree... Because he's explanation is way too good
@imfito3713
@imfito3713 2 жыл бұрын
Good video but didn't explain or I didn't understand what happens when 2 or more numbers are the same
Red-black trees in 4 minutes - Intro
3:54
Michael Sambol
Рет қаралды 730 М.
Quick sort in 4 minutes
4:24
Michael Sambol
Рет қаралды 1,9 МЛН
the balloon deflated while it was flying #tiktok
00:19
Анастасия Тарасова
Рет қаралды 10 МЛН
А что бы ты сделал? @LimbLossBoss
00:17
История одного вокалиста
Рет қаралды 10 МЛН
Good teacher wows kids with practical examples #shorts
00:32
I migliori trucchetti di Fabiosa
Рет қаралды 13 МЛН
Insertion sort in 2 minutes
2:19
Michael Sambol
Рет қаралды 1,3 МЛН
you will never ask about pointers again after watching this video
8:03
Big-O notation in 5 minutes
5:13
Michael Sambol
Рет қаралды 1,1 МЛН
3 Types of Algorithms Every Programmer Needs to Know
13:12
ForrestKnight
Рет қаралды 488 М.
Learn Selection Sort in 8 minutes 🔦
8:21
Bro Code
Рет қаралды 248 М.
The Midpoint Circle Algorithm Explained Step by Step
13:33
NoBS Code
Рет қаралды 94 М.
10 Sorting Algorithms Easily Explained
10:48
Coding with Lewis
Рет қаралды 72 М.
Heap sort in 4 minutes
4:13
Michael Sambol
Рет қаралды 1 МЛН
15 Sorting Algorithms in 6 Minutes
5:50
Timo Bingmann
Рет қаралды 24 МЛН
the balloon deflated while it was flying #tiktok
00:19
Анастасия Тарасова
Рет қаралды 10 МЛН