Selection sort algorithm

  Рет қаралды 1,310,774

mycodeschool

mycodeschool

Күн бұрын

See complete series on sorting algorithms here:
• Sorting Algorithms
In this lesson, we have described Selection sort algorithm and analyzed its time complexity.
Series on Time Complexity:
• Time Complexity Analysis
For updates on videos and courses, subscribe to our channel.
You may also like us on Facebook:
/ mycodeschool

Пікірлер: 365
@mycodeschool
@mycodeschool 11 жыл бұрын
Did you see our merge sort video? Its quite simplified. You may start loving recursion once it settles well in your head.
@nilamshanker4660
@nilamshanker4660 5 жыл бұрын
Cant we write if(arr[j]
@mycodeschool
@mycodeschool 11 жыл бұрын
This is almost like online tuition. You can ask questions and even request videos. We can try to get them. :)
@bubaighosh8500
@bubaighosh8500 4 жыл бұрын
My god . How could you know that ? Even I thought why this guy is not uploading videos.
@nithingunamgari871
@nithingunamgari871 4 жыл бұрын
@@bubaighosh8500 Nope, the person teaching is pretty much alive and is working at Google. (Animesh Nayan). However, another co-founder kinda guy (Harsha aka Humblefool) died in an accident. Those circumstances led to the closure of the channel.
@rameshchandrapola1102
@rameshchandrapola1102 3 жыл бұрын
@@oreoshake6287 no
@shubhamsulakhe3382
@shubhamsulakhe3382 2 жыл бұрын
@@shamanthakrishnakg1978 uff
@shankar7435
@shankar7435 4 ай бұрын
❤❤❤
@swetamahajan6416
@swetamahajan6416 6 жыл бұрын
These videos are really awesome.Please post more videos on C programming and if possible on java,python,c++ or any other language you want or on data structures and algorithms because you are doing a great job. Your videos helped me a lot.You make things simple and concise.
@mycodeschool
@mycodeschool 11 жыл бұрын
We are always comparing with A[iMin] i.e the current minimum,, so, its against 7, then against 4 and then against 2. Its not always against 7 because iMin is getting updated.
@bob_factory
@bob_factory 4 жыл бұрын
I saw a lot of comments below asking for new videos from this guy, This is 2020 and it has been 7 years since this video was posted and the content is top-notch. However the author is no more and suffered a loss of life by a speeding car while crossing a road. May he rest in peace.
@andrewdavies5722
@andrewdavies5722 4 жыл бұрын
hope that's not true
@shashiprabha9029
@shashiprabha9029 4 жыл бұрын
He is Animesh Nayan and he's alive
@MelDen-h9z
@MelDen-h9z Жыл бұрын
One of the greatest lecture of all time on algorithm!
@CSSoda
@CSSoda 4 жыл бұрын
Rest in Peace Harsha. You will be remembered through your amazing work.
@riyazbajishaik1596
@riyazbajishaik1596 4 жыл бұрын
He died?
@mohammadashraf1070
@mohammadashraf1070 4 жыл бұрын
@@riyazbajishaik1596 car accident 🙏🙏
@Plavokosi_Marko98
@Plavokosi_Marko98 4 жыл бұрын
Rest in peace. :,(
@kondowewilas-qe7hp
@kondowewilas-qe7hp 6 ай бұрын
Sad news. R.I.P😢😢
@dkp8230
@dkp8230 21 күн бұрын
Rest in peace 😢
@dileepbc5901
@dileepbc5901 5 жыл бұрын
dear sir, we are following ur entire content please update this course with more algorithms , please bros who like this series give thumbs . (from india)
@sarfaraz6582
@sarfaraz6582 5 жыл бұрын
brother, this guy is no more
@shubhampanwar6879
@shubhampanwar6879 4 жыл бұрын
@@sarfaraz6582 what happened to him
@sarfaraz6582
@sarfaraz6582 4 жыл бұрын
@@shubhampanwar6879 passed away years ago by car accident
@AbhishekSingh-hy4dm
@AbhishekSingh-hy4dm 4 жыл бұрын
@@sarfaraz6582 bro its not this guy its the other cofounder of the channel his friend who died..the guy who speaks in the video works for google now
@tanmaysrivatsa8550
@tanmaysrivatsa8550 5 жыл бұрын
It was difficult for me to understand but you made me understand in 10 minutes. Thanks
@davidgmos
@davidgmos 2 жыл бұрын
Great lesson, I think the final code can be optimized... void selectionSort(int* A, int n){ int temp; // temporary variable for (int i=0; i < n-1; i++){ // n-2 passes (last element comparisons are not necessary) for (int j=i+1; j < n; j++){ if (A[j] < A[i]){ // there's a smaller value ahead temp = A[i]; // interchange positions A[i] = A[j]; A[j] = temp; } } }
@saajankumarjha244
@saajankumarjha244 2 жыл бұрын
how's this optimized ? what you've done is nothing but bubble sort with swapping of min elements. Time complexity for both is O(n^2)
@davidgmos
@davidgmos 2 жыл бұрын
@@saajankumarjha244 yes that's optimization swapping elements only when needed, that implies fewer instructions per pass and less execution time even with the same time complexity
@saajankumarjha244
@saajankumarjha244 2 жыл бұрын
@@davidgmos here's a scenario for you consider an array {5,4,3,2,1}, let me know which one is optimized in terms of swapping.
@davidgmos
@davidgmos 2 жыл бұрын
@@saajankumarjha244 mine because in the worst case scenario (like the one you propose) swapping occurs through all the array and time execution is almost the same, but when it's not the case (like the vast majority of cases) the lines that swap positions in my code execute only when is necessary because they are inside the "if" condition.
@chelseakatsidzira7153
@chelseakatsidzira7153 5 жыл бұрын
some of the best material online period
@ayushcode5804
@ayushcode5804 4 жыл бұрын
Love his voice
@BNFY1
@BNFY1 Жыл бұрын
Such a masterpiece! It is still no.1 in 2023
@ryujiyamasaki355
@ryujiyamasaki355 2 жыл бұрын
Thank you so much, will probably binge watch your videos for my upcoming DSA exam
@anton.encours
@anton.encours 8 жыл бұрын
it probably would make sense to add another "if" statement, to check if the min is different from i (then swap is needed). Right now, we are swapping every time, even when it is not needed
@RajeevKumar-ch4kg
@RajeevKumar-ch4kg 5 жыл бұрын
Hi Anton, We are building a huge video tutorial of solutions which are asked in the interview. and we need your feedback on our video content. We believe that we can achieve that if you are around with us. So please come to our KZbin channel. The playlist link is as given below. kzbin.info/aero/PLqqPVCi6glKYJ3RK_LrlljjnAk5QdcroX Please subscribe the channel for any upload notification.
@chouliwen4173
@chouliwen4173 5 жыл бұрын
Actually,I also think about “if”,if it is added,the program is more efficient .
@jayjhaveri1906
@jayjhaveri1906 5 жыл бұрын
@@chouliwen4173 no.
@farazhusain925
@farazhusain925 4 жыл бұрын
I really appreciate your work...one of the best channel for DS & Algo...Please make more videos
@blake1835
@blake1835 5 жыл бұрын
Selection sort. In computer science, selection sort is a sorting algorithm, specifically an in-place comparison sort. It has O(n2) time complexity, making it inefficient on large lists, and generally performs worse than the similar insertion sort.
@blake1835
@blake1835 5 жыл бұрын
His definition of in-place for this algorithm that you showed makes sense but from other examples i see swaps and not copying values to a new array. In place means there is NOT a use of extra data structures that will be created then deleted. Selection sort is said to be an in place but you are saying it is not? is this explanation wrong or am I confused?
@unknownguywholovespizza
@unknownguywholovespizza 10 ай бұрын
@@blake1835 well it can be both in-place and not-in-place. Generally, not-in-place are used to make explanation easier. But in-place is much better.
@LUX1111111111111
@LUX1111111111111 11 жыл бұрын
I just love you. You teach the way I learn !
@hirakmondal6174
@hirakmondal6174 6 жыл бұрын
*_This guy sounds the same as the one on neso academy_*
@shubhampatel5576
@shubhampatel5576 6 жыл бұрын
yes , noticed
@anshul6516
@anshul6516 6 жыл бұрын
he also owns neso academy.
@usama57926
@usama57926 6 жыл бұрын
HIRAK MONDAL your comment is in bold. How you do that...
@RajKumar-qv7ci
@RajKumar-qv7ci 6 жыл бұрын
@@usama57926 *use "*" at start and end of comment*
@usama57926
@usama57926 6 жыл бұрын
@@RajKumar-qv7ci thank u very much
@annmaryjose7880
@annmaryjose7880 7 жыл бұрын
U saved my life
@rupaliroychoudhury2300
@rupaliroychoudhury2300 9 жыл бұрын
I think for selection sort, time complexity for best case should be O(n) because if one traverses through the already sorted list, then one can always come out of it after finding that it is already sorted instead of traversing again. Here is my code : int temp, min = 0, index = 0; bool swap = true; for(int i = 0; i < num && swap; i++) { min = arr[i]; swap = false; for(int j = i; j < num - 1; j++) { if(min > arr[j+1]) { min = arr[j+1]; index = j+1; swap = true; } } if(swap == true) { temp = arr[i]; arr[i] = min; min = temp; arr[index] = min; } }
@tej4o3
@tej4o3 Жыл бұрын
It's O(n^2) because of the nested for loop I think
@yahyayozo8660
@yahyayozo8660 3 жыл бұрын
very gratuful for you man , this really gave an overview of sorting algorithms
@SmartProgramming
@SmartProgramming 6 жыл бұрын
amazing explanation, hats off to you sir, keep it up 👍👍
@ventin75
@ventin75 8 жыл бұрын
The way you explain your selection sort and how you code your selection sort function is actually different in my opinion.
@blake1835
@blake1835 5 жыл бұрын
I also agree with this
@ahinsa__parmo__dharam
@ahinsa__parmo__dharam 3 жыл бұрын
Best explanation I ever found for sorting. Thanks alot sir for the easiest approaches you shared with us .😊😊
@Juznik1389
@Juznik1389 9 жыл бұрын
I LOVE YOU! Thanks for these clips!
@qaisurrehman7106
@qaisurrehman7106 4 жыл бұрын
Sir hats off to you the best lectures on sorts i have ever heard thankyou so much
@prayagparikh8020
@prayagparikh8020 5 жыл бұрын
It's too good👍👍 i understood very easily bro Your language accent is so good and sweet
@energizedphy6bybhathiyawij9
@energizedphy6bybhathiyawij9 9 жыл бұрын
This helps me a lot in my exam..thnkzzzzzz a lot
@juhabach6371
@juhabach6371 3 жыл бұрын
Dude, please keep making videos...we need you, even in 2021...please
@ankitatomar1343
@ankitatomar1343 2 жыл бұрын
in 2022 too
@anmol9886
@anmol9886 Жыл бұрын
But he died
@paramjeetchauhan
@paramjeetchauhan 8 жыл бұрын
thanks bro. your teaching way is impressive.....
@ronakpatil6081
@ronakpatil6081 3 жыл бұрын
this vid also taught me time complexity calculation wow! hats off....
@amittamrakar7661
@amittamrakar7661 4 жыл бұрын
*best lecture*
@beauty876
@beauty876 11 ай бұрын
You are good at teaching and creating panel Thank you
@Azmayenfayek
@Azmayenfayek 7 жыл бұрын
all da videos r just mind blowing
@souravjagati10
@souravjagati10 5 жыл бұрын
*nicely explained..loved it*
@TheMcallist1
@TheMcallist1 6 жыл бұрын
Amazing vids. Thanks for making them.
@bhaskerthapa6534
@bhaskerthapa6534 9 жыл бұрын
thank u soo much for these good tutorials.
@sudhanshusingh208
@sudhanshusingh208 3 жыл бұрын
Hi, I recently found out about your channel and why did you stop making videos you are so good at it. Its a request if you could upload more videos about cs if possible. Love your work
@swastiksharma6926
@swastiksharma6926 2 жыл бұрын
he died
@womanwhocode3032
@womanwhocode3032 2 жыл бұрын
@@swastiksharma6926 no Animesh nayan is alive
@VivanRangra
@VivanRangra Жыл бұрын
@@womanwhocode3032 the brain behind the channel that is Harish died and as a result Animesh is depressed and can not make more videos
@amritanair6640
@amritanair6640 7 жыл бұрын
There is a mistake at 2:37, it is supposed to be the second smallest element and not second-largest. Thank you for the videos, they are absolutely amazing :)
@bmrreddy2002
@bmrreddy2002 7 жыл бұрын
he probably meant to say 2nd largest within the sorted portion of the array.
@dunno4729
@dunno4729 3 жыл бұрын
You help me so much Thanks for your brilliant tutorial!!!
@RahulKumar-cg9sf
@RahulKumar-cg9sf 6 жыл бұрын
great work..it really very helpful
@jayshrinikam19
@jayshrinikam19 8 жыл бұрын
I found it complicated than other explanations..Why can t you have variable to hold the index of minimum value from each pass. Then swap the first element and the minimum element. So in next pass start from 2nd element to find second element and so on...
@sayyedaaman5719
@sayyedaaman5719 2 жыл бұрын
Thank you sir for that video it's very helpful for me
@silentcod3r
@silentcod3r 11 жыл бұрын
You mentioned that this algorithm is slow, but technically, it is not if n (size of the array) is small. As n gets bigger, it can begin to get slower yes.
@sanjanaattanayake4231
@sanjanaattanayake4231 Жыл бұрын
Thank you!!! Awesome teaching...
@JannisAdmek
@JannisAdmek 6 жыл бұрын
Normally I am not into correcting grammar mistakes but since you say it in every video: first not 1th great videos btw!!
@karanrandhir9865
@karanrandhir9865 6 жыл бұрын
First number will actually be the zeroth index . So 1th is said to avoid confusion .
@chingiskhant4971
@chingiskhant4971 5 жыл бұрын
You're so good!!!! Indian tutorials forever!
@sidneyeubanks8224
@sidneyeubanks8224 6 жыл бұрын
Great tutorials! Keep it up i appreciate it!
@tanm7610
@tanm7610 10 жыл бұрын
loving your videos!!
@tbtb3096
@tbtb3096 4 жыл бұрын
Totally worth that horrendous zomato ad
@harshjha7795
@harshjha7795 4 жыл бұрын
excellent explanation
@aishwaryaghosh4329
@aishwaryaghosh4329 5 жыл бұрын
Excellent explanation...we should make videos... excellent...
@mohitahlawat4944
@mohitahlawat4944 5 жыл бұрын
Great explanation
@geeky_world
@geeky_world 3 жыл бұрын
in 2021 also best series to learn Ds
@beardlessspirit4946
@beardlessspirit4946 9 жыл бұрын
please do the lecture for file pointers i.e, lecture on streams..... we are having a lot of trouble in learning that....... thank you for all the lectures till now.....
@pallabiguha7991
@pallabiguha7991 4 жыл бұрын
teacher: lets talk about simple sorting scenerio. teacher: *takes out adult uno cards*
@aviroxi
@aviroxi 3 жыл бұрын
lmao
@sagardolui2998
@sagardolui2998 7 жыл бұрын
amazing video, you make it so simple..
@moniruzzamanmoni676
@moniruzzamanmoni676 4 жыл бұрын
Excellent explanation :)
@eligirl100
@eligirl100 7 жыл бұрын
this was so helpful man. Thanks
@Kaustubh560
@Kaustubh560 11 жыл бұрын
Good job! Nice lecture! :)
@shivenpatro3602
@shivenpatro3602 4 жыл бұрын
Good work👍🏻👍🏻👍🏻
@naveenareddy9042
@naveenareddy9042 7 жыл бұрын
Nice,and easy,clear
@amanchauhan-jl9ls
@amanchauhan-jl9ls 11 жыл бұрын
Nice explanation.. but can you please upload video for Heap Sort and Radix sort?
@VishalKumar-lk1pt
@VishalKumar-lk1pt 10 ай бұрын
great lecture
@m.mubashar786
@m.mubashar786 3 жыл бұрын
*Amazing sir*
@amaan0
@amaan0 3 жыл бұрын
*Thanks Animesh*
@mikeyyychang8402
@mikeyyychang8402 6 жыл бұрын
instead of n could replace by array.length or return new arr[] will be more efficient
@christorok1906
@christorok1906 6 жыл бұрын
These are fantastic and very clear. Great video!
@kursemov7860
@kursemov7860 5 ай бұрын
álgorithm, not algórithm anyway, thanks for the video, man you are great!
@silverzero9524
@silverzero9524 7 жыл бұрын
Array bhai bhai bhai bhai
@aryamaangoswamy179
@aryamaangoswamy179 5 жыл бұрын
List behen behen behen behen
@RajeevKumar-ch4kg
@RajeevKumar-ch4kg 5 жыл бұрын
Hi Miscritz, We are building a huge video tutorial of solutions which are asked in the interview. and we need your feedback on our video content. We believe that we can achieve that if you are around with us. So please come to our KZbin channel. The playlist link is as given below. kzbin.info/aero/PLqqPVCi6glKYJ3RK_LrlljjnAk5QdcroX Please subscribe the channel for any upload notification.
@shubhamsulakhe3382
@shubhamsulakhe3382 2 жыл бұрын
@@aryamaangoswamy179 😂
@spaceandtechnology5214
@spaceandtechnology5214 2 жыл бұрын
😂😂😂😂😂😂
@iam_tanishmall
@iam_tanishmall 2 жыл бұрын
Bro😂😂
@nilashishchakraborty3983
@nilashishchakraborty3983 10 жыл бұрын
There is an issue with this algorithm. If u take inputs as 4,2,1,8 it gives back 2,1,4,8 as output. And it is not an issue of the code because the sorting algorithm itself specifies this sort of output it. Please check it :) P.S: I might be wrong ;)
@jef4300
@jef4300 10 жыл бұрын
it gives 1248 for me
@vishnuprabhaviswanathan546
@vishnuprabhaviswanathan546 7 жыл бұрын
Really superb..
@butterflybraganza
@butterflybraganza 5 жыл бұрын
Time complexity explanation was pretty vague. I felt the second expression should be (n-2)(n-2)C2/2
@debajyotideori
@debajyotideori 3 жыл бұрын
*very helpful*
@rohitsinghal100
@rohitsinghal100 11 жыл бұрын
nice explanation... thank you for these videos..
@usama57926
@usama57926 6 жыл бұрын
thank u sir amazing algorithm thanks again
@aseemlalfakawma5084
@aseemlalfakawma5084 7 жыл бұрын
Thanks dude.
@SaratKumar-qk7lu
@SaratKumar-qk7lu 5 жыл бұрын
Hello, Thanks! for the Explanation. It's good to start for learning. I have a small doubt. At present we have shortcuts are available like Arrays.sort(), Arrays.parallelSort(); Comparable and Comparator etc., We need to learn this sorting Algorithm._ (I don't know that's the reason I am asking.) _.*It anyone knows please provide the answer. * Please provide any links. I need to learn more about this. Thanks and Regards, Sarat.
@JoeJoseph79
@JoeJoseph79 4 жыл бұрын
There are predefined sorting methods . These sorting algorithms are just choices in case we need to implement algorithms based on input size.
@MegaGangsta4life
@MegaGangsta4life 10 жыл бұрын
I love your accent xD
@mycodeschool
@mycodeschool 10 жыл бұрын
MegaGangsta4life - Thanks bro :)
@AyushKalani2
@AyushKalani2 9 жыл бұрын
mycodeschool Full desi tadka , Nice
@monicaslv323
@monicaslv323 8 жыл бұрын
+MegaGangsta4life Me tooo!!!!
@SadSilentSlim
@SadSilentSlim 8 жыл бұрын
+mycodeschool Where you from?
@moumitasen6453
@moumitasen6453 8 жыл бұрын
+Abdurrahman AKAL India
@fitnessislifelong
@fitnessislifelong 3 жыл бұрын
Why i
@m2tdev
@m2tdev 2 жыл бұрын
thnks
@nayeembadhusha4759
@nayeembadhusha4759 6 жыл бұрын
Please provide videos on heap sort also
@abhinashmahor6227
@abhinashmahor6227 9 жыл бұрын
please upload a lecture on linkedlist
@Pradeepkahera
@Pradeepkahera 7 жыл бұрын
Superb..
@sourabhguptaurl
@sourabhguptaurl 11 жыл бұрын
thank you!
@shahriarhaqueabir7687
@shahriarhaqueabir7687 8 жыл бұрын
your tutorials r like my home tutor..:v thank you so much. but the subtle slide hinders understanding sometimes
@anshumansharma6334
@anshumansharma6334 6 жыл бұрын
Explanation is very congested and hastened. Go over the points a bit more patiently
@akarrshsrivastava7310
@akarrshsrivastava7310 6 жыл бұрын
Just a suggestion!!!!!!!!!!!!!!!!!!!!WE dont need to swap even if the chosen i element is already minimum in global array
@aneeshtiwari6893
@aneeshtiwari6893 5 жыл бұрын
*thank you so much sir*
@dhineshbabu7275
@dhineshbabu7275 9 жыл бұрын
It's really nice...
@8147333930
@8147333930 7 жыл бұрын
Thanks a lot
@RathourShubham
@RathourShubham 3 жыл бұрын
*nice one*
@nitpal9958
@nitpal9958 2 жыл бұрын
Why use iMin at all? Why not simply use i instead of iMin? We can do the comparison A[j] < A[i] and it will give the same result. void SelectionSort(int A[], int n) { for (int i=0; i
@anmol9886
@anmol9886 Жыл бұрын
Just for sake of better understanding
@mondal1839
@mondal1839 4 жыл бұрын
*Splendid*
@likithasahukari457
@likithasahukari457 6 жыл бұрын
Thank you sir.....
@miguelpetrarca5540
@miguelpetrarca5540 3 жыл бұрын
nth term in arithmetic series is calculated by a (sub n) = n ( (a1 + a (sub n) )/ 2 ) , if last term is 1, and first is (n-1), how do you get n(n-1) / 2
@जयश्रीराम-ब7म
@जयश्रीराम-ब7म 6 жыл бұрын
thanks
@unknownguywholovespizza
@unknownguywholovespizza 10 ай бұрын
There's an error in the pseudocode. It's: for i
@venkatasubbareddy.g2283
@venkatasubbareddy.g2283 5 жыл бұрын
Could you make the data structures and algorithms videos using java
@RajeevKumar-ch4kg
@RajeevKumar-ch4kg 5 жыл бұрын
Hi Venkata, We are building a huge video tutorial of solutions which are asked in the interview. and we need your feedback on our video content. We believe that we can achieve that if you are around with us. So please come to our KZbin channel. The playlist link is as given below. kzbin.info/aero/PLqqPVCi6glKYJ3RK_LrlljjnAk5QdcroX Please subscribe the channel for any upload notification.
Bubble sort algorithm
10:24
mycodeschool
Рет қаралды 1,7 МЛН
Insertion sort algorithm
14:15
mycodeschool
Рет қаралды 1,5 МЛН
Can You Find Hulk's True Love? Real vs Fake Girlfriend Challenge | Roblox 3D
00:24
Мама у нас строгая
00:20
VAVAN
Рет қаралды 11 МЛН
One day.. 🙌
00:33
Celine Dept
Рет қаралды 44 МЛН
The IMPOSSIBLE Puzzle..
00:55
Stokes Twins
Рет қаралды 183 МЛН
7.5 Selection Sort in Data Structure | Selection Sort Algorithm with C Program
17:49
Jenny's Lectures CS IT
Рет қаралды 1,4 МЛН
Merge sort algorithm
18:20
mycodeschool
Рет қаралды 2,2 МЛН
Analysis of Merge sort algorithm
18:21
mycodeschool
Рет қаралды 547 М.
Quicksort algorithm
20:39
mycodeschool
Рет қаралды 1,8 МЛН
Selection Sort Algorithm - Theory + Code
18:49
Kunal Kushwaha
Рет қаралды 254 М.
Understanding the Time Complexity of an Algorithm
24:59
Neso Academy
Рет қаралды 53 М.
Learn Selection Sort in 8 minutes 🔦
8:21
Bro Code
Рет қаралды 267 М.
Selection Sort Tutorial in Java: The Snail's Guide to Sorting
14:17
Coding with John
Рет қаралды 59 М.
Can You Find Hulk's True Love? Real vs Fake Girlfriend Challenge | Roblox 3D
00:24