What is the worst and the best time complexity for nested for
loop?
int compare(int n, int A[][]) {
int i, j, k, m;
for (i=1; i<=n; i++) {
for (j=1; j<=n; j++) {
for (k=1; k<=n; k++) {
for (m=1; m<=n; m++) {
if (A[i][j] == A[k][m] && !(i==k && j==m))
return 1;
}
}
}
}
return 0;
}
I tried to solve it on my own but getting really confused on how the inner most loop will add to the complexity.