0

I have this Java code for matrix multiplication:

double[][] product(double[][] x, double[][] y) {
    double[][] z = new double[x.length][y[0].length];
    for (int i = 0; i < x.length; i++) {
        for (int j = 0; j < y[0].length; j++) {
            double sum = 0.0;
            for (int k = 0; k < x[0].length; k++) {
                sum += x[i][k]*y[k][j];
            }
            z[i][j] = sum;
        }
    }
    return z;
}

What is the time complexity of this algorithm ? Can I say it is O(n^3) ?

Eritrean
  • 15,851
  • 3
  • 22
  • 28
user3275222
  • 225
  • 3
  • 12

1 Answers1

1

Yes I think it is O(n^3) since you have three loops inside each other