i am writing function to find the position where the target value should be inserted in the given array. We assume the array has distinct values and is sorted in ascending.
here i want the time complexity to be O(logN).
public static int FindPosition(int[] Arr, int element)
{
int i; int u=0;
{
for(i=0;i<Arr.length;i++)
{
if(element>Arr[i])
u++;
}
}
return u;
}
does this program have time complexity of O(log n). can any one help me with changes to function so it can be in o(log n).