Given the array , during the counting sort algorithm, what does the array look like when it is first completed (before any modification)?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Relevant wiki: Counting Sort
The C array keeps track of how many of each value there is in A . Each index in C corresponds to a value in A . For example, the 0th index in C will contain an integer that equals the number of times 0 appears in A .
If we go through A and count the number of each value, we get:
Number of 0's in A = 1 Number of 1's in A = 2 Number of 2's in A = 1 Number of 3's in A = 2 Number of 4's in A = 4 Number of 5's in A = 2 Number of 6's in A = 2 Number of 7's in A = 1 Number of 8's in A = 1 Number of 9's in A = 1
Therefore, C = [ 1 , 2 , 1 , 2 , 4 , 2 , 2 , 1 , 1 , 1 ] .