| preferred AP College board partner for AP classes
Login
 
Register
AP Computer Science A/Unit 10: Recursion
Start Practice Test
Share
Maximum Recursion Depth
< Prev
Next >

Consider the following MaxDepth class. What is the maximum recursion depth when the main method is executed?

public class MaxDepth {
    public static int process(int[] arr, int low, int high) {
        if(low >= high) return 1;
        int mid = (low + high) / 2;
        int left = process(arr, low, mid);
        int right = process(arr, mid+1, high);
        return Math.max(left, right) + 1;
    }
    
    public static void main(String[] args) {
        int[] data = new int[16];
        System.out.println(process(data, 0, data.length - 1));
    }
}
A

4

B

6

C

16

D

5

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