|
|
|
|
|
by nlogn
5223 days ago
|
|
He's right actually if the code is written sensibly. Well it should really be (N-1)! but close enough. Think about it in terms of 3 balls. I check ball1 against ball2 and ball3 then move to ball2. It gains me nothing to re-check ball2 against ball1 so I just check it against ball3. When I reach ball3, I have already checked everything and I'm done. The loop should look like this: for (i = 0; i < n; ++i)
for (j = i + 1; j < n; ++j)
|
|