D

We will break down your problem by understanding it in smaller problems by imagining a complete execution, we execute max on an array of 8 elements: int[]arr = {0,1,2,3,4,5,6,7};
//Aquí entramos en la ejecución principal
int max = Max(arr,0,arr.lenght.1);
first execution i is 0, j is 7 (first and last position of the array), is inserted into the clause else, calculates the midpoint (3) and executes again two instances of the code://Ejecución principal:
max_left = Max(arr,0,3); //Es decir {0,1,2,3}
max_right = Max(arr,4,7); //Es decir {4,5,6,7}
It's important for you to see that here the execution jumps back to the head of the function, because we have to calculate max_left for the most general case, therefore the second execution will have to wait, we get into the first "sub-execution", that is to say Max(arr,0,3). Here i and j remain unlike, so it will again divide the execution into 2, the parts of the array {0.1} and {1,2} and will again subdivid as in the previous one, that is to say//Sub ejecución 1
max_left = Max(arr,0,1);
max_right = Max(arr,2,3);
We follow again with "max_left", because that variable has not yet been filled, it is easy to see that the next execution will be//Sub ejecución 2
max_left = Max(arr,0,0); //i=j=0
max_right = Max(arr,1,1); //i=j=1
We continue with max_left, receive i = 0 and j= 0, so here we get into the if, returning arr[0] (value 0 because it is the first position). //Sub ejecución 3
return arr[0];
At this time we have reached a base case so in Sub Execution 2 we are happy, at this moment max left is equal to 0max_left = ... //Ejecutado y con valor 0
max_right = Max(arr,1,1); //Por ejecutar, devolverá el valor 1
Max_right's execution will return 2 in the same way as sub-execution 3 (we are at the same level). Think that at the same level we will have 8 sub executions (not executed at the same time) Max(arr,0,0); Max(arr,1,1) ... Max(arr,7,7) Ejecución general (0,7)
Max_left / Max_right \
Nivel 1(0,3) Nivel 1(4,7)
L / R \ / \
(0,1) (2,3) (4,5) (6,7)
L / R\ / \ / \ / \
(0,0) (1,1) (2,2) (3,3) (4,4) (5,5) (6,6) (7,7)
At this point we find 0.1 with the Right and Left variables full, so we climb a level in the tree that I have painted above. That level is ready to compareif (max_left > max_right)
return max_left;
else
return max_right;
Thus it will return the maximum between 0 and 1, which in this case will be 1 and will be stored in right. Upon reaching a sentence return We will raise a level in the tree, in this case at (0.3), who will already have the left variable filled and will have to fill the right, so it will lower to the level (2.3), hence it will fill its variables with (2) and (3) and return the highest value (3), filling the Right variable of (0.3) and allowing to fill the left of (0.7) and go down to the branch (4.7). So on will be compared to the end at the level (0.7) levels 3 and 7 and the highest value will be returned, 7 in this case.