Time Complexity Of Nested Loops
What is the time complexity of the above nested loops?
public class NestedLoop {
public static void main(String[] args) {
int[][] arr = new int[rows][cols]; // assume dimensions: n rows and m columns
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length; j++) {
for (int k = 0; k < j; k++) {
// constant time operation
int temp = arr[i][j] + k;
}
}
}
}
}
A
O(n*m)
B
O(nmlog m)
C
O(n²*m)
D
O(n*m²)
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE