Time Complexity of Nested Loops
Assuming matrix[i][j] can be as large as k in the worst case, what is the time complexity of the above code?
public class VariableInnerLoop {
public static void process(int[][] matrix) {
for (int i = 0; i < matrix.length; i++){
for (int j = 0; j < matrix[i].length; j++){
for (int k = 0; k < matrix[i][j]; k++){
// constant operation
int dummy = k;
}
}
}
}
}
A
O(n + m + k)
B
O(nmk)
C
O(n*m)
D
O(n*m + k)
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE