How to do a Counting Sort -- O(n + k) Time & Space Complexity

preview_player
Показать описание

Please check my playlists for free DSA problem solutions:

Best Courses for Analytics:
---------------------------------------------------------------------------------------------------------

Best Courses for Programming:
---------------------------------------------------------------------------------------------------------

Best Courses for Machine Learning:
---------------------------------------------------------------------------------------------------------

Best Courses for Statistics:
---------------------------------------------------------------------------------------------------------

Best Courses for Big Data:
---------------------------------------------------------------------------------------------------------

More Courses:
---------------------------------------------------------------------------------------------------------

Full Disclosure:
Please note that I may earn a commission for purchases made at the above sites! I strongly believe in the material provided; I only recommend what I truly think is great. If you do choose to make purchases through these links; thank you for supporting the channel, it helps me make more free content like this!
Рекомендации по теме
Комментарии
Автор

Master Data Structures & Algorithms For FREE at AlgoMap.io!

GregHogg
Автор

Doesn't work if you have negative elements.
I think it would be better to check for both the minimum and the maximum elements, and make an array of size (max-min+1)

stevenhany
Автор

thanks sir your quick recap helped me lot and I got placed in Zoho.

coderunner
Автор

comment for youtube algo. Good content. Thank you.

Dogberto
Автор

Spce complexity should be O(max(arr)) only why is it O(n+max(arr))?

rushikeshchaure
Автор

Sorry newbie question here! For the O(n + max(arr)) could you explain more on “+ max(arr)” part?

iiiyadex
Автор

This is really cool, I can't believe we weren't taught it in my Algorithms class.
One thing I'd do differently is have the for loop iterate over range(max_val+1) instead, since range(len(count)) would unnecessarily compute the len at every iteration making your loop O(n^2)

Could you also let me know if the max(arr) is a very large value, would that be a problem?

akrammohamed
Автор

Q> Isn't this type of sorting algorithm bad if big numbers are in the middle?

asagiai
Автор

How come so hard to understand your explanation?

iseeflowers
Автор

Sounds like an extended Dutch flag problem

simonbauer