Reputation: 2739
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
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 value
s. You don't get them if you simply loop over the counts and regenerate the key
s.
Upvotes: 1