Learn Counting Sort Algorithm in LESS THAN 6 MINUTES!

preview_player
Показать описание
Step-by-step guide to counting sort with a visual example. Counting sort is useful when the range of values each item can take is very small.

For example, you can use if if you want to sort 10,000 people according to their age. We can safely assume (for now) that no human is older than 199 years old, so the range of values is very small in this case.
Рекомендации по теме
Комментарии
Автор

... Holy crap, this makes so much sense.
You count how many of each digit there is, and then you determine each digit's starting position by counting how many cells are taken up by the digits before it!

theyoungster
Автор

after watching many videos, i can proudly say that i'm still confused af!!!

skylerdjy
Автор

Huh, this makes a lot of sense actually. Very well explained.

NemoK
Автор

I came for an in-depth explanation of why we do the accumulative additions and was not disappointed. Thank you!

Liam-bprm
Автор

Great explanation! keep up the good work. Love your teaching style very much.

FYI - For anyone who would like a Python version of counting sort based on his explanation.

def counting_sort(arr):
# step 1. find max
mx = max(arr)

# step 2. count frequency and store counts in the 'count' array
count = [0 for _ in range(mx + 1)]
for item in arr:
count[item] += 1

# step 3. compute the max position of each number based on
# the frequency stored in the 'count' array
for i in range(1, len(count)):
count[i] += count[i-1]

# step 4. shift values in 'count' by one to the right
for c in range(len(count)-1, 0, -1):
count[c] = count[c-1]
count[0] = 0

# step 5. fill the result array
res = [0] * len(arr)
for item in arr:
idx = count[item]
res[idx] = item
count[item] += 1

# done!
return res

ployapinon
Автор

"Simplicity is the final achievement, It's the crowning reward of art." The Guru who thought of this?

shawnswitchhagan
Автор

that was an awesome explanation. I have been trying to get it for a while. I don't understand why he stopped making videos. This is awesome content.

arpit
Автор

you're actually a genius at explaining this. Thank you!

arsalansyed
Автор

Woah, that is really cool! So simple yet so effective!

devincory
Автор

I was trying to figure this out for 2 hours to use this in radix sort and I after I figured this out I saw your video and then I realised that I have wasted two hours thank you for your help I can understand your video easily .thank you

marishlakshmanan
Автор

I love u ~~ hahaha. Good job on explaining the time complexity. feel confused after I saw MIT open course, and your series of video solve it~

Han-unog
Автор

This is so easy to understand! I finally got what my prof was talking about. Thank you so much!

KM-dhst
Автор

after many articles and videos and this video I can say I got this. thanks man

danhle
Автор

Fabulous! This makes so much more sense than reading wikipedia or geeksforgeeks :) Great explanation!

maripaz
Автор

Thank you so much. This makes a lot of sense.

Rajat-Sharma
Автор

This was an extremely easy to understand explanation! Thanks a lot.

minefacex
Автор

Wonderful explanation, thanks a lot !

eladbenatar
Автор

This is the best explaination ever!! Thank you very much <3

quocnguyeninh
Автор

Before I watched this I thought that I know how counting sort works.
During the video I had no idea what the heck is going on here.
After watching this I kind of know how it works.
So this video made me realize that I have yet something to learn! Thanks for making videos, maybe this one wasn't really helpful but your other tutorials and videos are really awesome and inspiring!

martynazielinska
Автор

Do I need to keep track of the numbers that never occur in the range?

moritzshore