edited by
667 views
0 votes
0 votes
given a sorted array of distinct integers A[1........n], you want to find out whether there is an index i for which A[i]=i.if this problem is solved using divide and conquer method ,then the algorithm run in

a) O(n)               a) O(nlogn)            a) O(logn)         a) O(n2)
edited by

1 Answer

Best answer
1 votes
1 votes

Ans- 0(logn)

Algorithm

int special_search(int a[],int l,int r)

{

   int mid;

   if(l<r)

     {

         mid=l+(r-l)/2;

         if(a[mid]==mid)   return mid;

         else if(a[mid]>mid) return special_search(a,l,mid-1);

          else return(a,mid+1,r)

    }

}

Related questions

1 votes
1 votes
1 answer
2
meethunjadhav asked Jul 30, 2018
438 views
suppose merge sort takes 2 sec to sort a set of 64 keys then how much time will take to sort a set of 512 keys?here, ans is 24 sec how it is plz explain me.
0 votes
0 votes
1 answer
4
Shailendra Patel asked Nov 1, 2016
382 views
Merging K sorted list each of size n/k into one sorted list of n-elements using Heap Sort will take how much time?