I have to write a function in C which takes as input an array and the dimension of the array. We assume that the array has the following characteristics:
- Every element in the array is different
- the first elements of the array are odd and the remaining are even
- There are at least one odd element and one even element in the array
The function has to return the first index of the even elements using a divide and conquer approach and the cost of the algorithm should be O(log(n)).
In a normal case, I would use a function like this:
int foo(int v[], int n){
for(int i=0; i<n; i++){
if(v[i]%2==0)
return i;
}
}
But I have no idea how to solve this problem with the divide and conquer approach. Is it possible to solve the problem using a modified version of the mergesort o quicksort algorithm?