Shell Sort Comparisons/Exchanges Counter I need to analyze shell-sort. Currently I am working with it having an increment of N/2. I will then go on to try more efficient increments.

However, my count for comparisons/exchanges seems too low for an array of 2000 elements. I've tried changing it around some but still everything seems too low. Could someone look over my code and see if my counters are in the right places?

public class Sort {
    static int exchanges= 0;
    static int comparisons= 0;

    public static void SegmentedInsertionSort (AnyType[] array, int N, int gap)
    {
        for (int index = gap ; index &lt; N ; index++)
        {
            AnyType temp;
            int j = index - gap;
            while (j &gt;= 0)
            {
                  comparisons++;
                  if (array[j].isBetterThan(array[j+gap]))
                  {
                       temp = array[j];
                       array[j] = array[j + gap];
                       array[j + gap] = temp;
                       j = j - gap;
                       exchanges++;
                  }
                  else j = -1;
            }
        }
    }

    public static void shellSort (AnyType[] array)
    {
        int N = 2000;
        int gap = N/2;
        while (gap &gt; 0)
        {
            SegmentedInsertionSort(array, N, gap);
            gap = gap / 2;
        }
    }
}


Also, I know there are other ways to code this, but the pseudo-code template I was given by my professor looked like this.
Your counting code seems correct.
comparison increments on each compare operation,
exchanges increments only on exchange.

On reversed array of 2000 elements I have got: comparison = 26416 and exchanges = 10400 

\$log_{2000} {26416} \approx 1.34\$
So you have \$O(n^{1.34})\$ complexity.
Which is between \$O(n^{3/2}) = O(n^{1.5})\$ and \$O(n^{5/4}) = O(n^{1.25})\$
So according to wiki it's okay for usual gap sequence.
exchanges = 10400 is less then average move count \$0.41N\ln N (\ln \ln N + 1/6)\$ which in case of N = 2000 is approximately 13500, but it depends on gap sequence. E.g if you start with gap = N / 8 it will be equal to 14400.