Counting Sort explained with animations and example | Full implementation and code

  Рет қаралды 12,815

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Counting Sort is an algorithm which does not use comparison to perform sorting. It works in a O(n) time complexity but there is a certain caveat. It compromises on space to give you a better time complexity. Counting sort is usually applied with some special use cases when you know the range of elements beforehand. In this video watch a live demonstration how it works behind the scenes followed by a dry-run of the code. This way the concept will stay in your mind forever.
00:00 - Intro
01:14 - Where do you use Counting Sort?
03:43 - Live Demo of Counting Sort
11:04 - Dry-run of code
15:09 - Final Thoughts
📚 Links I talk about in the video:
Bubble Sort: • Bubble Sort Algorithm ...
Insertion Sort: • Insertion Sort visuali...
Selection Sort: • Selection Sort | Live ...
Merge Sort: • Merge Sort with Visual...
Quick Sort: • Quick Sort super easy ...
Time Complexity: • What is the Time Compl...
📘 A text based explanation is available at: studyalgorithms.com/array/cou...
Code on Github: github.com/nikoo28/java-solut...
TestCases on Github: github.com/nikoo28/java-solut...
🔗 To see more videos like this, you can show your support on: www.buymeacoffee.com/studyalg...
💻 Get Social 💻
Follow on Facebook at: / studyalgos
Follow on Twitter at: / studyalgorithms
Follow on Tumblr at: / studyalgos
Subscribe to RSS feeds: studyalgorithms.com/feed/
Join fan mail: eepurl.com/g9Dadv
#algorithm #sorting #tutorial

Пікірлер: 30
@charlesopuoro5295
@charlesopuoro5295 2 жыл бұрын
Great job. Thank you very much for taking the time to careful explain the Counting Sort Algorithm. It is one thing to know, it is another to inform or impart knowledge. You have done so. Thanks again.
@mariaghorayeb5986
@mariaghorayeb5986 2 жыл бұрын
So useful ! You explain amazingly well ! Keep it up !!
@ssthil1
@ssthil1 8 ай бұрын
Perfect, it's clear to understand. Appreciated 👏🏼
@aliyanshaikh1547
@aliyanshaikh1547 Жыл бұрын
Honestly, brother, you are godsent. Thanks so much for this video. You are one of the only channels I have seen that dry-run code together. I enjoyed every moment of this video
@nikoo28
@nikoo28 Жыл бұрын
Thank you for such a kind comment. Wish you all the luck in this upcoming year
@prashansapunjabi
@prashansapunjabi Жыл бұрын
Really cool explanation! Thanks.
@ayabc4320
@ayabc4320 3 жыл бұрын
Very useful! Thank you 🙏✨
@chetansai4275
@chetansai4275 2 жыл бұрын
A very good lecture .Thank you sir
@rojidansari6394
@rojidansari6394 Жыл бұрын
What a great explanation 👍👍👍
@maisharana5405
@maisharana5405 3 жыл бұрын
thanks for the knowledge and it will help me to do my assignment.
@ebrahimkassem8939
@ebrahimkassem8939 2 жыл бұрын
Very helful and very good explanation.. Thank you sooo much
@funnymoment9164
@funnymoment9164 8 ай бұрын
Thanks!
@shortandshine8279
@shortandshine8279 3 күн бұрын
Gr8, thanks, could you please explain why cumulative and placing in output array with -1, should work
@mohamedndaloma1383
@mohamedndaloma1383 2 ай бұрын
Great video by the way it was very helpful. Quick question though why do we have 6 occurances of 2 and just a single occurance of 3 when there should be 2 occurance of 3 and 5 of 2 when sorting the array for the final result?
@shortandshine8279
@shortandshine8279 3 күн бұрын
Also for negative numbers how to make it work in python
@anniamatthews6803
@anniamatthews6803 Жыл бұрын
Can you please make a video explaining and solving "The full counting sort" problem on hackerrank?
@vinethasuresh3488
@vinethasuresh3488 Жыл бұрын
you mentioned counting sort follows stable in video?what is mean by stable sir?
@nikoo28
@nikoo28 Жыл бұрын
stable means that the ordering of elements does not change.
@user-gh3yn7mq5y
@user-gh3yn7mq5y 5 ай бұрын
Since we're also finding a maximum and minimum number in the array. Isn't there a time complexity also involved in that?
@nikoo28
@nikoo28 4 ай бұрын
finding the maximum and minimum happens in O(n)
@thellaidhinesh8646
@thellaidhinesh8646 Жыл бұрын
Hey nikhil, I saw a lot of videos related to counting sort, yours is very easy to understand. Keep the good work going. The only issue is, I found the audio was not up to your explanatory skills. So please do consider some improvements in audio
@nikoo28
@nikoo28 Жыл бұрын
Do check my recent videos. I have fixed the audio :)
@wish7479
@wish7479 2 жыл бұрын
Hi sir, I have a doubt If I have integer arry={1,5,2,10,11,20} If you sort this array using Arrays.sort() - > o/p 1,10,11,2,20,5 Why it is sorting based on ASCII value? Why not sequentially 1,2,5,10,11,20 If you take list of string having alphanumeric type, how we can sort alphanumeric Ally. I am not able to solve this. Can you help me on this? Arrays.sort()-
@nikoo28
@nikoo28 2 жыл бұрын
Can you DM me on the email address in channel description.
@wish7479
@wish7479 2 жыл бұрын
@@nikoo28 sure sir
@wish7479
@wish7479 2 жыл бұрын
@@nikoo28 sir, I have sent mail to you.kindly look into it.
@mohdsalimullah2608
@mohdsalimullah2608 2 жыл бұрын
Superstar
@saurabhsoni738
@saurabhsoni738 2 жыл бұрын
Please explain the code too
@nikoo2805
@nikoo2805 2 жыл бұрын
Starting at 11:04, you will see the code explanation
@etiennedegaulle3817
@etiennedegaulle3817 2 жыл бұрын
Bad audio and doesn't account for negative numbers.
Count Sort Algorithm - Theory + Code
20:44
Kunal Kushwaha
Рет қаралды 16 М.
Looks realistic #tiktok
00:22
Анастасия Тарасова
Рет қаралды 11 МЛН
БОЛЬШОЙ ПЕТУШОК #shorts
00:21
Паша Осадчий
Рет қаралды 8 МЛН
ИРИНА КАЙРАТОВНА - АЙДАХАР (БЕКА) [MV]
02:51
ГОСТ ENTERTAINMENT
Рет қаралды 11 МЛН
10 Sorting Algorithms Easily Explained
10:48
Coding with Lewis
Рет қаралды 36 М.
Counting Sort: An Exploration of Sorting Special Input In Linear Time
17:28
Merge Sort with Visuals and Animations | Study Algorithms
16:38
Nikhil Lohia
Рет қаралды 3,6 М.
Explaining EVERY Sorting Algorithm (part 1)
35:35
Kuvina Saydaki
Рет қаралды 161 М.
Learn Merge Sort in 13 minutes 🔪
13:45
Bro Code
Рет қаралды 266 М.
Max Consecutive Ones (LeetCode 1004) | Full Solution w/ animations
14:41
100+ Linux Things you Need to Know
12:23
Fireship
Рет қаралды 155 М.
Big O Notation, Time Complexity | DSA
21:17
Telusko
Рет қаралды 55 М.
Looks realistic #tiktok
00:22
Анастасия Тарасова
Рет қаралды 11 МЛН