I have this algorithm that calculates the matrix determinant using recursive divide-and conquer-approach:
int determ(int a[max][max],int max) {
int det=0, p, h, k, i, j, temp[max][max];
//base case omitted
for(p=0;p<max;p++) {
h = 0;
k = 0;
for(i=1;i<max;i++) {
for( j=0;j<max;j++) {
if(j==p) {
continue;
}
temp[h][k] = a[i][j];
k++;
if(k==max-1) {
h++;
k = 0;
}
}
}
det=det+a[0][p]*pow(-1,p)*determ(temp,max-1);
}
return det;
}
I want to optimize the main loop (with a loop unwinding or any strategy that can reduce the execution time). Any suggestion?