Assume you have a function that returns the difference in length between two arrays, however, it's not using the conventional methods to find length but rather a recursive function.
Can you help me find a loop invariant? I understand the loop invariant is something that must be true before the condition and after the condition. However, I am not really able to understand it. Here's the code:
function func (int arr1_length, int arr2_length) {
if (arr1_length == 0 && arr2_length == 0) return 0;
if (arr1_length == 0) return arr2_length;
if (arr2_length == 0) return arr1_length;
return func (arr1_length-1, arr2_length-1);
}
The first call is func(arr1.length, arr2.length);