Answer:
See explaination
Step-by-step explanation:
Binary(A,low , high )
if low> high
return -1
mid= (high+low)/2
if(A[mid]=1) and ((mid=0) or (A[mid-1]==0)) then
return mid
else if A[mid==1] then
return Binary(A,low,mid-1)
else
return Binary(A,mid+1,high)
Having in mind that the given array is a sorted array, we can simply use the binary search here, to find either lower bound of 1 or upper bound of 0.
I am explaining here by finding the lower bound 1.
You can see in the algorithm that, each time our size is getting reduced by half, so overall complexity of this algorithm is O(logn).