• edited by
1,783 views
1 1 vote

Given a sorted array of distinct integer $A\left [ 1,2,....n \right ]$, the tightest upper bound to check the existence of any index $i$, for which $A[i]=i$ is equal to _______________


I thought here answer that mean time complexity will be $O(1),$ because directly getting the searching index and then checking if $A[i]=i$, but answer given as $O(log n).$Please help me out, which will be correct answer?

1 Answer

0 0 votes
using binary search it will take O(logn)

mid=low+high/2

compare      (key > mid)

                 mid+1,high

                     (key<mid)

                low, mid-1
Position:
Show:

Related questions

3 3 votes
3 3 answers
3.1k
3.1k views
srestha asked May 12, 2019
3,111 views
An array $A$ of size n is known to be sorted except for the first $k$ elements and the last $k$ elements, where $k$ is a constant. Which of the following algorithms will ...
6 6 votes
1 1 answer
3.8k
3.8k views
srestha asked May 18, 2019
3,759 views
Consider a procedure $find()$ which take array of $n$ integers as input, and produce pair of element of array whose difference is not greater than the difference of any o...
0 0 votes
1 answers 1 answer
1.4k
1.4k views
srestha asked Apr 20, 2019
1,364 views
for(k=1;k<(n+1);k++) { for(m=1;m<(n+1);m+=k){ x=x+1; } }What is the T.C. of the following code?Is it $n^{2}$ or $n\log n$??
1 1 vote
1 answers 1 answer
915
915 views
srestha asked May 6, 2019
915 views
Through an experiment, it is found that selection sort performs $5000$ comparisons when sorting an array of size $k.$ If the size of array is doubled, what will be the nu...