tags:

views:

55

answers:

2

I think the Big-O notation is n^2, but im not too sure.

for (int i = 0; i < n -1; i++) {
    for (int j = 0; j < n – 1; j++)
        if (x[j] > x[j+1]) {
            temp = x[j];
            x[j] = x[j+1];
            x[j+1] = temp;
        }
}
+1  A: 

You are doing N * (N * (4)) operations = O(N^2)

BrokenGlass
A: 

Yes it's n^2. Ignore the constants, outer loops run n times, and inner loop runs n times for each n.

Andy Pryor