Click to See Complete Forum and Search --> : step counting this algorithm


-EquinoX-
February 12th, 2008, 06:18 PM
the code is:



w = 0;
while (true){
k = 0;
while (a[k] == nil){
k = k + 1;
if (k == n+1)
System.exit();
}

w = w +1;
b[w] = a[k]
c[w] = 1;
a[k] = nil;
for (int j = k+1; j<n; j++){
if (a[j] == b[w]){
c[w] = c[w] + 1;
a[j] = nil;
}
}
}


I am confused of how many times the second while loop is executed. As far as I know it's executed n(n+1)/2 times. Can someone help me to clarify this?