edited by
1,157 views
0 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)

1 Answer

Best answer
1 1 vote

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)

    }

}

Position:
Show:

Related questions

0 0 votes
1 answers 1 answer
1.0k
1.0k views
1 1 vote
1 1 answer
796
796 views
meethunjadhav asked Jul 30, 2018
796 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.
1 1 vote
1 answers 1 answer
1.0k
1.0k views
Emankashyap asked Apr 30, 2024
1,046 views
In quick sort, n numbers the (n/10)th element is selected as pivot using n^2 sortimng time complexity what will be the time complexity of quick sort is.....a)O(nlogn)b)O(...
1 1 vote
1 1 answer
919
919 views
chetan raghav asked Sep 3, 2017
919 views
Given an unsorted array. The array has this property that every element in array is at most k distance from its position in sorted array where k is a positive integer sma...