#include <stdio.h>
int main()
{
int a[]={6,9,5,3,3,2,0,0,-1,-4};
int low=0,high=10;
int i= findarray(a,low,high);
printf("%d\n",i);
return 0;
}
int findarray(int *p,int b,int c)
{
int mid=(b+c)/2;
if(p[mid-1]<p[mid])
{
if(p[mid]<p[mid+1])
return findarray(p,mid+1,c);
else return mid;
}
else return findarray(p,b,mid);
}
This is the programme to find the ith element position and it finds with in a time complexity of O(logn)
For the above input it returns '1' as value .