retagged by
2,523 views
1 votes
1 votes
Given a sorted array of distinct integers A[1,2,3,..,n], the tightest upper bound to check the existence of any index i for which A[i]= i is equal to O($n^{a}log^{b}n)$. Then a+10b is equal to ___?
retagged by

1 Answer

0 votes
0 votes

If the array had A[i]=i,∀iA[i]=i,∀i, then the complexity would have been θ(1)θ(1) as then all we need to check whether the length of the array is greater than the element or not. If it's greater we have the element, else we haven't.

But the array isn't like that. Array could be like 1,3,4,8,9,121,3,4,8,9,12 as well.

The question is asking to find an element A[i]A[i] in the sorted list which is situated at the index ii.

The algorithm to find such element is mere a slight modification of binary search where you update low & high based on i<A[i]i<A[i] - if it's true update high=mid-1 else if i>A[i]i>A[i] update low=mid+1. The complexity is indeed θ(log2n)

https://cs.stackexchange.com/questions/108642/finding-an-element-in-array-whose-index-number-and-element-value-same

Answer:

Related questions

0 votes
0 votes
1 answer
1
Sambhrant Maurya asked Aug 6, 2018
726 views
How to calculate the time complexity for finding repeated elements in an array of n elements using linear search and binary search?
2 votes
2 votes
1 answer
2
2 votes
2 votes
2 answers
3
Rohan Mundhey asked Nov 9, 2016
5,461 views
How many comparisons are needed for a binary search in a set of 64 elements?