Counting Sort Algorithm: Step by step visualization using an example

preview_player
Показать описание
EDIT: in B at index 8, the number should be 5. I mistakenly put 9 (which was the accumulative occurrence of 5). Thanks to @Rafal Krzychowiec.

A complete example of how counting sort algorithm actually works, and how it is related to its pseudo code.
Counting Sort is a stable sort and it can be used as a sub-routine for Radix Sort.
In case your range of numbers in the input array A does not start from zero (let's say starts from the number x), you can easily create another array A1, where
A1[j] = A[j] - x;
and then sort A1 instead of A. This way, the numbers in A1 will be the same numbers of A with a deduction of x. So numbers in A1 will start from 0. After the sort on A1 is done, simply re-generate A, by adding x back to each number of A1.

Рекомендации по теме
Комментарии
Автор

I wonder why professors do not explain things like this. Succinct and extremely helpful. Thank you.

BenNelsonillegalnumbers
Автор

your explanation is brilliant, thank you!

Hannah-lyff
Автор

I have no programming experience and I can understand this, even the symbolic writing outside the boxes. Excellent demonstration! 

adamboyle
Автор

Your method is perfect and stable, i really like the fact that you explained it with the speudocodes !!

lamaalhumaid
Автор

Thanks, girl. You teach better than my professor.

monicaslv
Автор

Thanks a lot! Finally, I understand the counting sort, after watching so many useless videos.

dr_
Автор

Thank you. Your video is by far the best.

GrumpyCodeMonkey
Автор

You explain this in a very easy way. The index of new C  and C itself at the index are swapped when you fill B values (the final result). The index of new C becomes a value in B at that C value.

frankpickerson
Автор

This is a perfect explanation, the concept is very clear now, I hope you have more videos as I am subscribing right away

NickyD
Автор

Thanks Emma for given wonderful lesson on counting sort algorithm

thequizclassroom
Автор

Awesome video. Plz add more topics with complexity analysis.

SunilSingh
Автор

Thank you so much whoever made this video, this video is extremely helpful. you explain it with details, which is great. awesome!!!!

danielroodson
Автор

u saved my day.. i've been searching for this kind of delivery.. great lecture

arslanali
Автор

Thanks you my Lady, You help me with one problem which not covered in other videos!

danex
Автор

All of my doubts about counting sort were cleared after I watched this.. So thanks and keep up the good work ^^

aiarcadecode
Автор

@Rafal Krzychowiec: You're right. My mistake! B should contain all the original numbers of A in a sorted order. So, in index 8 of B, we should put the number 5. I mistakenly put 9 (which was the accumulative occurrence of 5).

emmaa
Автор

Keep up the good work, really appreciate it..

mustafaujjainwala
Автор

Interesting, you told everything straight didn't tried to make it look academical, nice work!

ZnSstr
Автор

Really really nice!!! simply superb way of explanation.. thumbs up !!!!

rammohan
Автор

thank you explained in very easy way.. thanks again

AmbiguousAbhi