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

Time Complexity of Nested Loops

Mark
< Prev
Next >

The process method is shown below. Assume that matrix is a 2D array with n rows and m columns, and that the maximum value of any element in matrix is k. What is the worst-case time complexity of the method?

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(n*m)

C

O(nmk)

D

O(n*m + k)

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|