Recursion Question ?
Understand What’s the difference b/w them ?
Will both provide different output ?
Which among them executes quickly ?
Which among them has more recursive calls or big recursive tree ?
static int[] findMinMaxNumber1(int arr[], int index){
if(arr.length==index){
return new int[] {Integer.MAX_VALUE,Integer.MIN_VALUE};
}
return new int[] {Math.min(arr[index],findMinMaxNumber1(arr, index+1)[0]), Math.max(arr[index],findMinMaxNumber1(arr,index+1)[1])};
}
static int[] findMinMaxNumber1(int arr[], int index){
if(arr.length==index){
return new int[] {Integer.MAX_VALUE,Integer.MIN_VALUE};
}
int arr1[] = findMinMaxNumber1(arr, index+1);
return new int[] {Math.min(arr[index], arr1[0]), Math.max(arr[index], arr1[1])};
}