Question: Give an efficient solution to determine if there exists an integer i such that A i = i in an array of integers A 1

Give an efficient solution to determine if there exists an integer i such that Ai = i in an array of integers A1 < A2 < A3 < .....< An .

The naive and basic approach is to do the sequential search. Sequentially look at every item in the array and find whether there is a match for A[i] = i for any index i. The worst-case runtime of this algorithm is O(N), N being the size of input.

Please Note that, the array is sorted in ascending order. Can you find a better (more efficient than O(N)) solution to this problem?

Write down the better algorithm (in Pseudocode) and show the worst case and best case run time (using big-oh notation) of the algorithm

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!