You need to define what a unit of work is, i.e. how you are going to measure the work. Usually its either the time taken for computation, or each operation performed in the algorithm is assigned a unit of work. I suspect you mean the latter. In which case, why not just have an int, which is initially zero, which you increment each time 'a unit of work' is done? For example, increment this work counter each time a variable has its value assigned, a variable is incremented, a calculation is performed, etc. Then its just a matter of figuring out n^2 (in this case, num.length^2)...

E.g.:

Code:

public static void insertionSort( int[] num )
{
int i, j;
int workCount = 0;
int n2;
for(i = 0; i < num.length; i++)
{
int index = num[i];
j = i;
/*
comparison, increment, 2x assignment = 4 ops
*/
workCount += 4
while ((j > 0) && (num[j-1] > index))
{
num[j] = num[j-1];
j = j - 1;
/*
2x comparison, 3x decrement, 2x assignment = 7 ops
*/
work += 7
}
num[j] = index;
workCount++;
}
n2 = num.length * num.length;
System.out.println("work = " + workCount + ", work/n^2 = " + workCount/n2);
}

Although you could interpret what constitutes a 'work unit' differently to that...