Say I have the unsorted array = [(3,a), (1,p), (3,c), (7,f), (5,g), (3,b), (7,d), (8,w)].
My count array will be = [1,0,3,0,1,0,2,1]. For example, count[1] means that the frequency of element 1 is 1. (Assume index starts at 1 and not 0).
So, if we just use the count array, then the sorted array will be [1,3,3,3,5,7,7,8].
To get the sorted array, we are just appending element i count[i] times into an array where i in the range [1,8] for this specific example. We do this by iterating on count array.
Now I know one issue is that the data associated with the positive integers are discarded. This is one issue.
We can see that we are not using the elements from the input array (unsorted array). We are simply appending element i count[i] times.
So, since the above counting sort just appends i count[i] times and not directly using elements from the input array (unsorted array), is that the reason why it's not considered stable for the above example?
The notes I am reading on says "No, because it counts the values but does not distinguish between them" to the question "Is counting sort stable?" for the specific example above but I am having a hard time understanding what it means to say "but does not distinguish between them".
Thank you for any insight.