Two elements having the same value appear in the same order in the sorted sequence as they did in the input sequence.

Counting Sort is a Stable Sort.

Array A:

5 (1) | 7 | 3 (1) | 5 (2) | 2 | 1 | 4 | 3 (2) |

Array B:

1 | 2 | 3 (1) | 3 (2) | 4 | 5 (1) | 5 (2) | 7 |

If we change line from

for j = length(A) downto 1

to
for j = 1 to length(A)

- Would the algorithm still sort? Yes
- Would the algorithm still be a stable sort? No