Done counting sort little different.can u tell me where my code fails?
Hello @dbhavanishankar89,
There are issues with this program:
-
It is not counting sort, as you are not counting anything.
-
Your code is storing x and minimum element is a, then it will be done at fre[x-a] .
Example:
5
1 3 2 6 5
Explanation:
minimum element: a=1
for x=1, location x-a=1-1=0
for x=3, location x-a=3-1=2
for x=2, location x-a=2-1=1
for x=6, location x-a=6-1=5
for x=5, location x-a=5-1=4 -
What if there are same elements in the inputted array?
This logic would fail.
Example:
6
1 3 2 6 5 5
Hope, this would help.
Give a like, if you are satisfied.
1 Like