code4fun
code4fun

Reputation: 2739

regarding counting sort

i have a silly doubt regarding counting sort.What is the need to get the cumulative sum of all indexes to get sorted array when we can just iterate through the "count" array to reproduce the sorted array by seeing the count for that index.Does it affect the efficiency?

Upvotes: 0

Views: 100

Answers (1)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272517

Because typically each element will be of the form {key,value}, where we're sorting by key. The output array needs to contain the values. You don't get them if you simply loop over the counts and regenerate the keys.

Upvotes: 1

Related Questions