title: Pseudocode for comparison counting algorithm
body: <p><strong>I'm working on a homework question for my algorithms class and I'm boggled by how this particular algorithm works. I already found the answer online so I'm not looking for answers, just some help working through the code step by step. From what I can figure out so far, the algorithm accepts an array of an unspecified length and through multiple iterations, sorts the numbers by comparing an individual element with smaller elements within the array. At the end of the iterations, it assigns each element a location index that specifies what order the elements should be arranged in to be in a non-decreasing order. But what I cannot figure out is how the second for-do loop start off the iteration after the first loop is completed? Any assistance would be greatly appreciated</strong></p>
  
  <p>Question: Consider the algorithm for the sorting problem that sorts an array by counting, for each of 
  its elements, the number of smaller elements and then uses this information to put the 
  element in its appropriate position in the sorted array. Sort the following list of numbers, (60, 35, 81, 98, 14, 47):</p>
  
  <pre><code>Algorithm ComparisonCountingSort(A[0..n − 1], S[0..n − 1])
  //Sorts an array by comparison counting
  //Input: Array A[0..n − 1] of orderable values
  //Output: Array S[0..n − 1] of A’s elements sorted in nondecreasing order
  
  for i ← 0 to n − 1 do
       Count[i] ← 0
  
  for i ← 0 to n − 2 do
       for j ← i + 1 to n − 1 do
            if A[i] &lt; A[j]
                 Count[j] ← Count[j] + 1
            else
                 Count[i] ← Count[i] + 1
  
  for i ← 0 to n − 1 do
       S[Count[i]] ← A[i]
  
  return S
  </code></pre>