| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice TestPractice Test
About Exam
hard Solved by 1 students
Time Complexity Of Nested Loops
< Prev
Next >

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²)

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy