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?
Share
Because typically each element will be of the form
{key,value}, where we’re sorting bykey. The output array needs to contain thevalues. You don’t get them if you simply loop over the counts and regenerate thekeys.