Video není dostupné.
Omlouváme se.

Selection sort algorithm

Sdílet
Vložit
  • čas přidán 6. 06. 2013
  • 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

Komentáře • 364

  • @mycodeschool
    @mycodeschool  Před 11 lety +234

    This is almost like online tuition. You can ask questions and even request videos. We can try to get them. :)

    • @bubaighosh8500
      @bubaighosh8500 Před 4 lety

      My god . How could you know that ? Even I thought why this guy is not uploading videos.

    • @nithingunamgari871
      @nithingunamgari871 Před 4 lety +14

      @@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 Před 3 lety

      @@oreoshake6287 no

    • @shubhamsulakhe3382
      @shubhamsulakhe3382 Před 2 lety

      @@shamanthakrishnakg1978 uff

    • @shankar7435
      @shankar7435 Před 5 dny

      ❤❤❤

  • @mycodeschool
    @mycodeschool  Před 11 lety +88

    Did you see our merge sort video? Its quite simplified. You may start loving recursion once it settles well in your head.

  • @bob_factory
    @bob_factory Před 4 lety +18

    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.

  • @swetamahajan6416
    @swetamahajan6416 Před 6 lety +18

    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  Před 11 lety +34

    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.

  • @CSSoda
    @CSSoda Před 3 lety +12

    Rest in Peace Harsha. You will be remembered through your amazing work.

  • @farazhusain925
    @farazhusain925 Před 4 lety +1

    I really appreciate your work...one of the best channel for DS & Algo...Please make more videos

  • @user-zg9no2de8x
    @user-zg9no2de8x Před rokem +1

    One of the greatest lecture of all time on algorithm!

  • @Juznik1389
    @Juznik1389 Před 8 lety +9

    I LOVE YOU! Thanks for these clips!

  • @tanmaysrivatsa8550
    @tanmaysrivatsa8550 Před 4 lety +3

    It was difficult for me to understand but you made me understand in 10 minutes.
    Thanks

  • @ryujiyamasaki355
    @ryujiyamasaki355 Před rokem

    Thank you so much, will probably binge watch your videos for my upcoming DSA exam

  • @yahyayozo8660
    @yahyayozo8660 Před 2 lety

    very gratuful for you man , this really gave an overview of sorting algorithms

  • @LUX1111111111111
    @LUX1111111111111 Před 10 lety +11

    I just love you. You teach the way I learn !

  • @ahinsa__parmo__dharam
    @ahinsa__parmo__dharam Před 3 lety +1

    Best explanation I ever found for sorting.
    Thanks alot sir for the easiest approaches you shared with us .😊😊

  • @sidneyeubanks8224
    @sidneyeubanks8224 Před 6 lety +2

    Great tutorials! Keep it up i appreciate it!

  • @chelseakatsidzira7153
    @chelseakatsidzira7153 Před 5 lety

    some of the best material online period

  • @bhaskerthapa6534
    @bhaskerthapa6534 Před 8 lety +3

    thank u soo much for these good tutorials.

  • @narsireddynallamilli3755
    @narsireddynallamilli3755 Před 10 lety +3

    Can we improve algo by running c3 only if iMin is changed in c2?

  • @SmartProgramming
    @SmartProgramming Před 6 lety +1

    amazing explanation, hats off to you sir, keep it up 👍👍

  • @qaisurrehman7106
    @qaisurrehman7106 Před 3 lety

    Sir hats off to you the best lectures on sorts i have ever heard thankyou so much

  • @hirakmondal6174
    @hirakmondal6174 Před 6 lety +213

    *_This guy sounds the same as the one on neso academy_*

    • @shubhampatel5576
      @shubhampatel5576 Před 6 lety +2

      yes , noticed

    • @anshul6516
      @anshul6516 Před 6 lety +5

      he also owns neso academy.

    • @usama57926
      @usama57926 Před 6 lety +1

      HIRAK MONDAL your comment is in bold. How you do that...

    • @RajKumar-qv7ci
      @RajKumar-qv7ci Před 5 lety +7

      @@usama57926 *use "*" at start and end of comment*

    • @usama57926
      @usama57926 Před 5 lety +3

      @@RajKumar-qv7ci thank u very much

  • @TheMcallist1
    @TheMcallist1 Před 6 lety +2

    Amazing vids. Thanks for making them.

  • @ayushcode5804
    @ayushcode5804 Před 4 lety +9

    Love his voice

  • @mcwho3
    @mcwho3 Před 8 lety

    Great video! This was a much clearer explanation than when i took this class in college. Quick question, why would you want/need to pass in the length of the array. Are you assuming that this is being implemented in languages without built in arrays with a find/return length function? It seems like it would be unnecessary for a user to input the length.

  • @tanm7610
    @tanm7610 Před 10 lety +1

    loving your videos!!

  • @energizedphy6bybhathiyawij9

    This helps me a lot in my exam..thnkzzzzzz a lot

  • @annmaryjose7880
    @annmaryjose7880 Před 7 lety +7

    U saved my life

  • @dunno4729
    @dunno4729 Před 2 lety

    You help me so much
    Thanks for your brilliant tutorial!!!

  • @prayagparikh8020
    @prayagparikh8020 Před 5 lety +1

    It's too good👍👍 i understood very easily bro
    Your language accent is so good and sweet

  • @sagardolui2998
    @sagardolui2998 Před 7 lety

    amazing video, you make it so simple..

  • @fayekfree
    @fayekfree Před 6 lety

    all da videos r just mind blowing

  • @paramjeetchauhan
    @paramjeetchauhan Před 7 lety +1

    thanks bro. your teaching way is impressive.....

  • @eligirl100
    @eligirl100 Před 6 lety

    this was so helpful man. Thanks

  • @ronakpatil6081
    @ronakpatil6081 Před 3 lety

    this vid also taught me time complexity calculation wow! hats off....

  • @BNFY1
    @BNFY1 Před rokem

    Such a masterpiece! It is still no.1 in 2023

  • @Kaustubh560
    @Kaustubh560 Před 11 lety +3

    Good job! Nice lecture! :)

  • @amanchauhan-jl9ls
    @amanchauhan-jl9ls Před 10 lety +1

    Nice explanation..
    but can you please upload video for Heap Sort and Radix sort?

  • @thecoolnewsguy
    @thecoolnewsguy Před 6 měsíci +1

    There's an error in the pseudocode. It's:
    for i

  • @RahulKumar-cg9sf
    @RahulKumar-cg9sf Před 6 lety +1

    great work..it really very helpful

  • @tali_ttal
    @tali_ttal Před 5 lety +1

    May I ask what is the algorithm used in wordscapes?

  • @beauty876
    @beauty876 Před 7 měsíci

    You are good at teaching and creating panel
    Thank you

  • @sanjanaattanayake4231
    @sanjanaattanayake4231 Před 11 měsíci

    Thank you!!!
    Awesome teaching...

  • @souravjagati7550
    @souravjagati7550 Před 5 lety +1

    *nicely explained..loved it*

  • @dileepbc5901
    @dileepbc5901 Před 5 lety +16

    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 Před 4 lety

      brother, this guy is no more

    • @shubhampanwar6879
      @shubhampanwar6879 Před 4 lety +1

      @@sarfaraz6582 what happened to him

    • @sarfaraz6582
      @sarfaraz6582 Před 4 lety

      @@shubhampanwar6879 passed away years ago by car accident

    • @AbhishekSingh-hy4dm
      @AbhishekSingh-hy4dm Před 4 lety +2

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

  • @juhabach6371
    @juhabach6371 Před 3 lety +1

    Dude, please keep making videos...we need you, even in 2021...please

  • @beardlessspirit4946
    @beardlessspirit4946 Před 9 lety +1

    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.....

  • @rohitsinghal100
    @rohitsinghal100 Před 10 lety +3

    nice explanation... thank you for these videos..

  • @techforhad
    @techforhad Před 6 lety

    Hi , Do you have Brute-force algorithms tutorial ? Please let me know asap ! Thanks

  • @moulisiramdasu6753
    @moulisiramdasu6753 Před 5 lety

    what if we have duplicate number in the list like two same numbers. How that one number will be arranged?

  • @ventin75
    @ventin75 Před 8 lety +1

    The way you explain your selection sort and how you code your selection sort function is actually different in my opinion.

  • @christorok1906
    @christorok1906 Před 6 lety

    These are fantastic and very clear. Great video!

  • @jayshrinikam19
    @jayshrinikam19 Před 8 lety +10

    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...

  • @Burak-pl1jl
    @Burak-pl1jl Před 6 lety

    Wouldn't the part with the cost "c1" be executed "n - 2" times? Since you are starting with the index 0 till n-2
    which makes
    (n - 2) - 0 + 1 = n - 1
    for the loop header of the outer loop. Then n - 2 for the statements inside the loop.

  • @amritanair6640
    @amritanair6640 Před 7 lety +2

    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 Před 6 lety

      he probably meant to say 2nd largest within the sorted portion of the array.

  • @sourabhguptaurl
    @sourabhguptaurl Před 10 lety +1

    thank you!

  • @usama57926
    @usama57926 Před 6 lety +1

    thank u sir amazing algorithm thanks again

  • @sayyedaaman5719
    @sayyedaaman5719 Před 2 lety

    Thank you sir for that video it's very helpful for me

  • @naveenareddy9042
    @naveenareddy9042 Před 7 lety

    Nice,and easy,clear

  • @blake1835
    @blake1835 Před 4 lety +1

    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 Před 4 lety

      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?

    • @thecoolnewsguy
      @thecoolnewsguy Před 6 měsíci

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

  • @moniruzzamanmoni676
    @moniruzzamanmoni676 Před 4 lety

    Excellent explanation :)

  • @anton.encours
    @anton.encours Před 8 lety +56

    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 Před 5 lety

      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 CZcams channel. The playlist link is as given below.
      czcams.com/play/PLqqPVCi6glKYJ3RK_LrlljjnAk5QdcroX.html
      Please subscribe the channel for any upload notification.

    • @chouliwen4173
      @chouliwen4173 Před 4 lety

      Actually,I also think about “if”,if it is added,the program is more efficient .

    • @jayjhaveri1906
      @jayjhaveri1906 Před 4 lety +1

      @@chouliwen4173 no.

  • @mohitahlawat4944
    @mohitahlawat4944 Před 4 lety

    Great explanation

  • @silentcod3r
    @silentcod3r Před 10 lety

    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.

  • @rupaliroychoudhury2300
    @rupaliroychoudhury2300 Před 8 lety +2

    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 Před rokem

      It's O(n^2) because of the nested for loop I think

  • @harshjha7795
    @harshjha7795 Před 3 lety

    excellent explanation

  • @rolandoaguilera3114
    @rolandoaguilera3114 Před 7 lety

    what about an array like this {3,2,1} will it still work?

  • @miguelpetrarca5540
    @miguelpetrarca5540 Před 2 lety

    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

  • @vishnuprabhaviswanathan546

    Really superb..

  • @sudhanshusingh208
    @sudhanshusingh208 Před 2 lety +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 Před rokem +1

      he died

    • @womanwhocode3032
      @womanwhocode3032 Před rokem

      @@swastiksharma6926 no Animesh nayan is alive

    • @VivanRangra
      @VivanRangra Před rokem

      @@womanwhocode3032 the brain behind the channel that is Harish died and as a result Animesh is depressed and can not make more videos

  • @mikeyyychang8402
    @mikeyyychang8402 Před 5 lety

    instead of n could replace by array.length or return new arr[] will be more efficient

  • @aseemlalfakawma5084
    @aseemlalfakawma5084 Před 6 lety

    Thanks dude.

  • @davidgmos
    @davidgmos Před 2 lety +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 Před 2 lety

      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 Před 2 lety

      @@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 Před 2 lety

      @@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 Před 2 lety

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

  • @dhineshbabu7275
    @dhineshbabu7275 Před 8 lety

    It's really nice...

  • @VishalKumar-lk1pt
    @VishalKumar-lk1pt Před 6 měsíci

    great lecture

  • @shahriarhaqueabir7687
    @shahriarhaqueabir7687 Před 8 lety +1

    your tutorials r like my home tutor..:v
    thank you so much.
    but the subtle slide hinders understanding sometimes

  • @tanzeelrana7348
    @tanzeelrana7348 Před 7 lety

    beautiful !

  • @karankapoor2116
    @karankapoor2116 Před 10 lety

    great videos sir.. :)

  • @aneeshtiwari6893
    @aneeshtiwari6893 Před 4 lety

    *thank you so much sir*

  • @aishwaryaghosh4329
    @aishwaryaghosh4329 Před 5 lety

    Excellent explanation...we should make videos... excellent...

  • @m.mubashar786
    @m.mubashar786 Před 3 lety

    *Amazing sir*

  • @siddhantsalunke596
    @siddhantsalunke596 Před 6 lety

    Bro i have s question how it scans only min element y nt element next to u n tell me which is j and which is i element

  • @pritamsarkar8830
    @pritamsarkar8830 Před 7 lety +1

    please give me the time complexity analysis link

  • @8147333930
    @8147333930 Před 6 lety

    Thanks a lot

  • @mohammodalemran8248
    @mohammodalemran8248 Před 8 lety +1

    helpful.. thanks :)

  • @likithasahukari457
    @likithasahukari457 Před 6 lety

    Thank you sir.....

  • @niazmehedi
    @niazmehedi Před 7 lety

    Please do a tut on counting sort, my mid is in November 1st :(

  • @amittamrakar7661
    @amittamrakar7661 Před 4 lety +1

    *best lecture*

  • @JannisAdmek
    @JannisAdmek Před 6 lety

    Normally I am not into correcting grammar mistakes but since you say it in every video: first not 1th
    great videos btw!!

    • @karanrandhir9865
      @karanrandhir9865 Před 5 lety

      First number will actually be the zeroth index . So 1th is said to avoid confusion .

  • @silverzero9524
    @silverzero9524 Před 6 lety +105

    Array bhai bhai bhai bhai

    • @aryamaangoswamy179
      @aryamaangoswamy179 Před 5 lety +9

      List behen behen behen behen

    • @RajeevKumar-ch4kg
      @RajeevKumar-ch4kg Před 5 lety +2

      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 CZcams channel. The playlist link is as given below.
      czcams.com/play/PLqqPVCi6glKYJ3RK_LrlljjnAk5QdcroX.html
      Please subscribe the channel for any upload notification.

    • @shubhamsulakhe3382
      @shubhamsulakhe3382 Před 2 lety

      @@aryamaangoswamy179 😂

    • @spaceandtechnology5214
      @spaceandtechnology5214 Před 2 lety

      😂😂😂😂😂😂

    • @iam_tanishmall
      @iam_tanishmall Před 2 lety

      Bro😂😂

  • @SaratKumar-qk7lu
    @SaratKumar-qk7lu Před 5 lety +4

    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 Před 4 lety +1

      There are predefined sorting methods . These sorting algorithms are just choices in case we need to implement algorithms based on input size.

  • @shivenpatro3602
    @shivenpatro3602 Před 4 lety

    Good work👍🏻👍🏻👍🏻

  • @harmandua7489
    @harmandua7489 Před 9 lety

    can u plz upload video Radix sort... I am not getting it through other videos available till now..

  • @abhinashmahor6227
    @abhinashmahor6227 Před 9 lety +1

    please upload a lecture on linkedlist

  • @geeky_world
    @geeky_world Před 3 lety

    in 2021 also best series to learn Ds

  • @ioanefeiqrishvili1617
    @ioanefeiqrishvili1617 Před 7 lety

    thanks dude

  • @yasinhilo8673
    @yasinhilo8673 Před 6 lety

    thanks a lot

  • @nayeembadhusha4759
    @nayeembadhusha4759 Před 5 lety

    Please provide videos on heap sort also

  • @debajyotideori
    @debajyotideori Před 2 lety

    *very helpful*

  • @ibrahimgadli2583
    @ibrahimgadli2583 Před 2 lety

    How did you get n(n-1)2 pls explain

  • @purpleswipe1717
    @purpleswipe1717 Před 7 lety

    Great Explanation !!!
    Btw which software do u use for writing things like this?