For [3,1,2,1], the count array records two 1s, one 2, and one 3 before output is assembled.
Read the related guide · · Bookmark this unique URL with Ctrl/Cmd+D.
Counting sort counts how often each key occurs and uses cumulative counts to place values without comparisons. Experiment with a small example and see each step update.
For [3,1,2,1], the count array records two 1s, one 2, and one 3 before output is assembled.
Read the related guide · · Bookmark this unique URL with Ctrl/Cmd+D.