Hi!
This is a counting sort algorithm. I want to change the last for
loop of it to for j<---1 to n
.
I know that this will be correct, but I want to show this for one of my friends. How can I write my reason for it? Please help me! Thanks.
Counting Sort(A[1,..n]) //C[1,...k] is the temporary memory and k is the range of integers
for i<-- 1 to k
C[i]<-- 0
for j<-- 1 to n
C[A[j]]<--C[A[j]]+1
for i<--2 to k
C[i]<--C[i]+C[i-1]
for j<--n downto 1
B[C[A[j]]]<--A[j]
C[A[j]]<--C[A[j]]-1