Are you taking CLEP classes? Try clep.ai
| 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

Mark
< Prev
Next >

What is the time complexity of the following code segment? Assume arr is a 2D array with n rows and m columns.

public class NestedLoop {
    public static void main(String[] args) {
        int[][] arr = new int[n][m]; // Array has 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(nmlog m)

B

O(n*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.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|