7.12 Counting Sort (Analysis and Code) | Easiest Explanation | Data Structure Tutorials

Поделиться
HTML-код
  • Опубликовано: 10 фев 2025
  • Jennys Lectures DSA with Java Course Enrollment link: www.jennyslect...
    Discussed Counting Sort Algorithm with its Code.
    Step by step guide showing how to Sort an Array using Count Sort. Analysis of Counting Sort (Time Complexity)
    DSA Full Course: https: • Data Structures and Al...
    ******************************************
    See Complete Playlists:
    C Programming Course: • Programming in C
    C++ Programming: • C++ Complete Course
    Python Full Course: • Python - Basic to Advance
    Printing Pattern in C: • Printing Pattern Progr...
    DAA Course: • Design and Analysis of...
    Placement Series: • Placements Series
    Dynamic Programming: • Dynamic Programming
    Operating Systems: // • Operating Systems
    DBMS: • DBMS (Database Managem...
    ***********************************************
    Connect & Contact Me:
    Facebook: / jennys-lectures-csit-n...
    Quora: www.quora.com/...
    Instagram: / jayantikhatrilamba
    #countingsort #jennyslectures #dsa

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

  • @rahuldey1182
    @rahuldey1182 2 года назад +81

    I think Jenny is the best on RUclips when it comes to explaining complex sorting algorithms. Count sort and Merge sort explanation by her is outstanding.

  • @Chadagon_of_the_Swolen_Order
    @Chadagon_of_the_Swolen_Order 5 лет назад +58

    You did an amazing job at explaining this.
    As others said, your explanation was crystal clear.
    The fact that you fully explained each step before writing the code was also really cool because that way you can understand the code way better.
    Thanks for sharing!

  • @andrey.smolennikov
    @andrey.smolennikov 5 лет назад +9

    I have spent hours to understand why we do running sum before final placement and you are the only one who explained it SO CLEARLY! Thank you so much!

  • @noorbajwa1845
    @noorbajwa1845 11 месяцев назад +2

    Mind-blowing no one teaches these complex things better than you,I'm loving to code because of you

  • @izzyv830
    @izzyv830 4 месяца назад +3

    Im leaving a comment for algorithm cuz its honestly criminal that this isnt the first video when you search for counting sort. Its literally the only one ive found that presents it in a way that makes sense.

  • @Hello-vt2bh
    @Hello-vt2bh 11 месяцев назад +1

    Your clear explanation of the counting algorithm was incredibly helpful. The step-by-step breakdown before delving into the code enhanced my understanding significantly. It's the most comprehensive explanation of counting sort I've come across after exploring multiple sources. Keep up the excellent work!

  • @bardamu9662
    @bardamu9662 5 лет назад +6

    Great job! Very informative and crystal clear. I have gone through many videos trying to explain counting and radix sort aglorithms but none is as easy to understand as this one. Jenny has great teaching skills in elaborating on critical details and giving first the big picture. I wish all teachers would have the same skillset and approach. Most of the time, it is not because things are difficult that we do not dare to explain them in pedagogical manner, it is because we do not dare to peel out things in more comprehensible chunks that things are difficult.

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

    This is the best explanation for Count Sort you will come across in RUclips.

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

    Counting sort can be confusing. Switching between the index, the element value, different arrays... Jenny manages to make it all so easy to understand. And enjoyable too. That half and hour passed quicker than an episode of Southpark. Liked and subscribed!!

  • @study-me1oe
    @study-me1oe 7 месяцев назад +2

    Wow, this is the best video I've seen for count sort. And also provided some keen drawbacks with a quick solution for sorting negative numbers too.
    One thing I would like to add is, we can improve the count sort by reducing the k value by "mapping the elements of the array" to some smaller values.
    Eg: if we have an array like 683,610,672,699,601,642. Instead of creating a count array of size 699+1, we can create a smaller array by subtracting the smallest value 601 from all elements ⇉ 82,9, 71,98,0,41. Now we can create count array of size 99 instead of 700.
    We can improve the feasible range of K this way

  • @90_vrushabhjadhav43
    @90_vrushabhjadhav43 3 года назад +1

    I watch this video 3 times then i uderstand the example with code.
    The best teacher i have ever see in may engineering life thanks henny man for very deep and very accurate explanation love you from maharashtra.

  • @siddharthkshirsagar2545
    @siddharthkshirsagar2545 4 года назад +2

    This is the python code for this astounding explanation.
    And you delivered the algorithm so flawlessly, thank you.
    def counting_sort(array):
    n = len(array)
    k = max(array)
    count = [0] * (k + 7)
    output = [None] * (n)
    for i in range(0,n):
    count[array[i]] += 1
    for i in range(1,k + 1):
    count[i] = count[i] + count[i - 1]
    # count[i] += count[i - 1]
    for i in range(n - 1,-1,-1):
    output[count[array[i]] - 1] = array[i]
    count[array[i]] -= 1
    for i in range(0,n):
    array[i] = output[i]

  • @durumarthu
    @durumarthu 4 месяца назад

    Your explanation is so awesome and thank you for not overlooking all the small intermediate steps so that it’s understandable by anyone with varying degrees of knowledge and understanding of this topic. Also thanks for implanting the logic alongside. Awesome job! Clear and precise explanation. I’m subscribing.

  • @nickharalampopoulos
    @nickharalampopoulos 5 лет назад +30

    Thank you so much. This is the best explanation of the counting algorithm. It helped me particularly when you explained why we should start form the last element of the original array.

    • @dkgusai6463
      @dkgusai6463 4 года назад +2

      she said so" to maintain the stability"

  • @immortalsofar7977
    @immortalsofar7977 5 лет назад +19

    I actually learn something from Jenny's lectures, unlike my university professors. Keep up the great work! Greetings from Vancouver, Canada

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

      looks like university profs are terrible world wide huh

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

    Saw your video first time..... And i became a huge fan ma'am..... The way you explained every tiny things in detaaill.... Was just outstanding....

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

    The way she teach is so clean , easy to understand for me even my english is limited. thanks from vietnam

  • @Mandeep99
    @Mandeep99 4 месяца назад +2

    Love you mam you are the best one who teaches this topic in very simple manner ❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️❤️

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

    Easily one of best algorithm teachers on youtube.

  • @mayanksingh7814
    @mayanksingh7814 4 месяца назад +1

    This is the best explanation of counting sort PERIOD.

  • @ron6107
    @ron6107 4 года назад +7

    This was amazing! Awesome! You not only covered a LOT more than covered in similar lectures but your explanations were lucid and to the point. Thanks!

  • @hariomvitthala
    @hariomvitthala 4 месяца назад +1

    You are simply flawless.... loved your teaching methods!! Thanks a lot ma'am 🎉🙏

  • @poornachandra6767
    @poornachandra6767 10 дней назад

    I saw other videos with no proper explanation why doing that way in some steps and ended up here after 3-4 videos checked and you gave the best expalanation thanks

  • @thavarchandradamor9860
    @thavarchandradamor9860 4 года назад +2

    aap Devi ho , itna accha to hume kisi ne bhi padaya ...thanks a lot

  • @BSEss
    @BSEss 2 года назад +6

    East & West Miss Jenny is BEST ! , North & South Everyone is out !!!

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

    Best and clear explanation of Counting sort available on net.

  • @saritakumari-oh8fs
    @saritakumari-oh8fs 4 года назад +2

    It was a mistry for me until I see your explanation. Thank you

  • @anubhavkumar4268
    @anubhavkumar4268 5 лет назад +8

    Really is best explanation of "The Counting Algorithm" !!!

  • @Justsimransingh
    @Justsimransingh 4 года назад +6

    I am watching your dsa series from long time but literally... You are amazing seriously your knowledge is damn good your concepts are so clear and the way you explain each and everything is remarkable. The stability concept constrain me to comment you deserve to be appreciate...
    I am preparing for my placement I am a B.Tech Final Year Student and you are helping me a lot I shared your playlist with all my college friends because the best dsa series is By Jayanti Khatri Lamba on Jenny's Lecture.
    A big thanks to you for helping me ❤️

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

    My slow brain magically caught up to the idea of counting sort.
    You are a wizard, Jenny.

  • @umarrabiuel-yakub4690
    @umarrabiuel-yakub4690 5 лет назад

    at first I was saying the content is too long for me but believe me is worth waiting thank you xx you are the best

  • @lukemonaco9747
    @lukemonaco9747 4 года назад +1

    This is the best illustration of counting sort i have seen.

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

    very well explained, Thanks Maam
    Respect from Pakistan

  • @Mdt-24
    @Mdt-24 7 месяцев назад

    Thank you very much, i got confused with the cumulative counting array part, the other videos ive watched didnt really go into depth on how it worked to index the numbers to its correct places. Your video made me grasp this very quickly so again, a massive thank you.

  • @Lakn2s
    @Lakn2s 4 года назад

    Mam u r best apke samjhana ka tarika the way u explain the concept mujhe bahot accha lagta he or apke samjhana me ek clearity he jiske wajhese bahot jaldi samjh me aata he 😊👍👍👍👍
    Thank u so much mam😇

  • @saharrohani5136
    @saharrohani5136 5 лет назад +5

    This was the best of counting sort explanation. Thank you so much for this amazing video.

  • @joseardila1457
    @joseardila1457 4 года назад

    This is so far, the best explamation that I had seen. Amazing video. 😬😬😬

  • @madhusmitabhuyan6485
    @madhusmitabhuyan6485 5 лет назад +1

    your videos are very helpful to me during my exam times ....the day before exam i only used to listen your videos ...u explained each and every concepts so nicely.. i just love your teaching ... thank you so much mam for all these videos :) :)

  • @MahbubaPoly-c6u
    @MahbubaPoly-c6u 4 месяца назад

    OMG😲...your explanation😘 i have no word to say🥹🥹😘😘😘😘😘😘😘😘😘
    God bless you mam❤

  • @emmaguo619
    @emmaguo619 4 года назад +2

    The best explanation for counting sort!

  • @sripriyanagaraju7019
    @sripriyanagaraju7019 4 года назад

    Excellent teaching dear.
    Now on words , I am a big fan of you.
    Really Hatsof to you. Great Job.
    Heartly Thanks Alot.

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

    I have attended the best university in the world throught Jenny lectures. Thank u ma'am. Your teaching is the best.

  • @muhammadfaizsam8852
    @muhammadfaizsam8852 4 года назад

    thank u so much. i literally finding and watching so many videos but i have got my ans from here with clearly and briefly

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

    Thank you very much , explained very clearly , no chances of having any doubts , reminded me of real class in this time of boring online classes

  • @Joyddep
    @Joyddep 4 года назад +1

    Great explanation! This has a lot of application in terms of questions and really tricky to grasp.

  • @Άκης-θ2ε
    @Άκης-θ2ε 3 года назад

    man we need teachers like her , great job

  • @ABHINAVKUMAR-vh3ln
    @ABHINAVKUMAR-vh3ln 4 года назад +1

    Clear and deep explanation. Worth watching 30 min video. Everyone should watch it once and you will never forget Counting Sorting, at least the nice mam here haha. Nice explanation mam by the way.

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

    Excellent Mam , And Thanks from Bangladesh . I am very much helpful from this video .

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

    In this video Computer Science Engineering In Its Peak Level By The Help Of an Awesome Professor! Your Explanation is best Madam...! #Respect_From_Calcutta

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

    2hrs of cls in just 30mins❤ that too with clear cut explanation 🙏🙏

  • @ranjeetharishchandre9606
    @ranjeetharishchandre9606 5 лет назад +3

    i love how you say "for" 😘😘 Nice explanation 👌👌👌👍👍👍

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

    absolutely in admiration of your teaching style, thank you so much!!

  • @rahulsrinivas7989
    @rahulsrinivas7989 4 года назад +2

    Excellent explanation I ever heard in my whole life...

  • @vipul1246
    @vipul1246 4 года назад

    I am an art student and didn't understand a dime but i like watching madame.I will watch all her videos.

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

    you are best teacher for me the way you explain is just wow
    thank u very much mam

  • @raman-jn6yt
    @raman-jn6yt 5 лет назад +1

    you never fail to make an impact on learning something !!! Thanks for your efforts !!! Looking forward for your other videos...

  • @abhinavpratapsingh4445
    @abhinavpratapsingh4445 5 лет назад +1

    Thank u ma'am it helped a lot and your way of explaining is very descriptive which makes it easy to understand

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

    always heard recommendations about your channel, now I do know why. That was awesome, thank you)

  • @1998charan
    @1998charan 5 лет назад +3

    Good Counting sort explanation available in YT.
    P.S Tried all other channels and came here.

  • @_-6912
    @_-6912 5 лет назад +3

    You have covered important concepts. You are an excellent teacher

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

    jenny i love u take this ummah ummah 😘😘😘😘 no lecture would teach this subject better than u (getting educated + with gorgeous teacher )is adipoli comination

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

    what an amazing explanation, you are the best at this . many thanks to you ❤👏👏👏

  • @aishwaryalokhande4802
    @aishwaryalokhande4802 4 года назад +1

    Mam u are great!! i want you to be my teacher.......

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

    thank you maam.. You are a perfect example of "beauty with brain"

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

    Great explanation! Thank you! Especially thanks for explanation hot to make this sort stable.

  • @sripriyanagaraju7019
    @sripriyanagaraju7019 4 года назад

    Your so genius Sweety.
    You have thorough knowledge in subject/topic.
    I am really appreciating you.

  • @theartist8835
    @theartist8835 5 лет назад +11

    Thank you! You're doing a brilliant job 😬

  • @professionalyogameditation
    @professionalyogameditation 6 месяцев назад

    chaala baga chepparu madam..very good explanation amma

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

    wow thanks jenny for using an all-encompassing example!

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

    Thanks a million Ma'am 👍🙏God bless you 😇

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

    When everything fails...Jenny's Lecture just smash like Dhoni at last to win the match(exam)...❤️
    Thank you so much

  • @jithinmv6516
    @jithinmv6516 5 лет назад

    Best explanation I have seen so far for counting sort, It is just perfect mam :)

  • @SamiKhan-sb5ik
    @SamiKhan-sb5ik Год назад +3

    00:02 Counting sort is a non-comparison sort algorithm that sorts elements based on their keys.
    02:38 Counting Sort is applied when the array contains no negative values and the values are in the range of 0 to K.
    07:44 The video explains the process of counting sort.
    10:30 Counting sort involves finding the actual position of elements in the sorted array.
    15:52 Counting Sort is a stable sorting algorithm.
    18:17 To maintain the stability of the sorting algorithm, start from a particular index and decrement the values
    22:53 Counting Sort is a sorting algorithm that places elements in a sorted array using a count array.
    25:24 Count Sort is a linear time sorting algorithm that can sort elements in a given array.
    30:22 Counting Sort limitations and the need for Radix Sort
    Crafted by Merlin AI.

  • @shehryaramin1481
    @shehryaramin1481 4 года назад

    Life Saver ...Big Respect from Pakistan !!!!

  • @sidharthpanda8557
    @sidharthpanda8557 5 лет назад

    31 minutes is worth. Thanks for the simplest explanation.

  • @mrmarakazhutha
    @mrmarakazhutha 5 лет назад +2

    Amazing mam, i came across your channel during my interview prep, i am at microsoft usa now :)

    • @lovleshbhatt7797
      @lovleshbhatt7797 4 года назад

      can you please give me a referral ?? I am good at DSA

  • @utkarsh_ishan
    @utkarsh_ishan 4 года назад +1

    great ma'am. u r blessing to all CS students

  • @premverma8220
    @premverma8220 5 лет назад

    bhatreen isse gazab kisis ne bhi ni padhaya aaj tak

  • @shivnandantiwari7489
    @shivnandantiwari7489 5 лет назад

    Mam this counting sort video is best in entire you tube ...

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

    Thank you Jenny for your clear lectures!

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

    I have ever seen such a super explanation

  • @sonalidoifode-gholve540
    @sonalidoifode-gholve540 4 года назад +1

    Thank you so much mam for Explanation in detail

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

    You are a best teacher ❤️❤️❤️ love from Pakistan 😘🥰❤️

  • @therealaspirant1882
    @therealaspirant1882 5 лет назад

    very good explanation the same implementation i saw in coreman book happy that you are one who refered textbook before making video

  • @ratnabarot6567
    @ratnabarot6567 5 лет назад +1

    Thanks for sharing! Really good explanation. I loved watching every second of this video. Keep making more tutorials like this.

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

    You are so smart, mam. love you Mam. It feels so easy now.😃

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

    Thank you for the nice explanation. I have a qualifying algorithm exam and this helps me a lot!

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

    Wow! Why haven't I found your channel all this while? I've definitely subscribed

  • @KATRUVISALIKA
    @KATRUVISALIKA 4 года назад +1

    excellentt explanation

  • @rakeshpatel3683
    @rakeshpatel3683 5 лет назад +2

    beauty with brain,,,,,,awesome combination mam with respect.......

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

    Excellent,
    Executed in java and was successful.
    public class CountingSort {
    public static void main(String[] args) {
    int[] a = { 2, 1, 1, 0, 2, 5, 4, 0, 2, 8, 7, 7, 9, 2, 0, 1, 9, 4, 6, 2, 3, 6, 5, 8, 7, 4 };
    //int[] a = {432,8,530,90,88,231,11,45,677,199};
    //This will take more space and time if done with counting sort , so we use radix sort
    int numberOfElements = a.length;
    int maximumInRange = getMaxInArray(a);
    countSort(a, numberOfElements, maximumInRange);
    }
    private static void countSort(int[] a, int size, int maximumInRange) {
    System.out.println("Before Sort :");
    for (int i = 0; i < size; i++) {
    System.out.print(a[i] + " ");
    }
    System.out.println();
    int[] count = new int[maximumInRange + 1];
    for (int i = 0; i < size; i++) {
    ++count[a[i]];
    }
    for (int i = 1; i = 0; i--) {
    b[--count[a[i]]] = a[i];
    }
    System.out.println("After Sort :");
    for (int i = 0; i < b.length; i++) {
    System.out.print(b[i] + " ");
    }
    }
    private static int getMaxInArray(int[] a) {
    int max = a[0];
    for (int i = 1; i < a.length; i++) {
    if (a[i] > max) {
    max = a[i];
    }
    }
    return max;
    }
    }

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

    Hey, you are teaching superb, this video is very useful to my university education. Thank you so much.

  • @satyamebjayate3730
    @satyamebjayate3730 4 года назад

    very nice & simple explanation . ...really it's very useful. .. .Good job Jenny

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

    Nice explanation. It is an very clear and deep explanation...

  • @zeeshanmughal9413
    @zeeshanmughal9413 4 года назад

    Thanks mam, your explaining skills are very eloquent.

  • @1maheshvk
    @1maheshvk 6 месяцев назад

    absolutely great with minute details

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

    Best 😊

  • @showviksalman1453
    @showviksalman1453 5 лет назад +1

    Mam you are so talented and also worked hard to makes these videos

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

    Your lesson inspire me very much thank you dear

  • @PankajKumar-mv8pd
    @PankajKumar-mv8pd 4 года назад +1

    Thank you so much. You explained it very well.