How to determine the range of frequency array in counting sort?

how to find the maximum element in array to find the range of freq array for counting sort?

Hello @sgupta_2001

You can loop through the elements of the array and maintain an interger say “maximum” and update the value of “maximum” when some integer greater than “maximum” is encountered.

int maximum = 0;
for(int i = 0; i < size; i++) {
     if(arr[i] > maximum) {
     maximum = arr[i];
     }
} 

This way you can get the maximum element of the array.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.