0%
0 / 15 answered

Informal Run-Time Analysis Practice Test

15 Questions
Question
1 / 15
Q1

A student counts how many pairs of different values appear in an int[] of size $n$.


public static int countDifferentPairs(int[] data) {

    int count = 0;

    for (int i = 0; i < data.length; i++) {

        for (int j = i + 1; j < data.length; j++) {

            if (data<u>i</u> != data<u>j</u>) {

                count++;

            }

        }

    }

    return count;

}

What is the run-time complexity of the algorithm in the code snippet?

Question Navigator