Menu

(Solved) : Given Sorted Array S 1 N N Distinct Numbers E Numbers Array Arranged Increasing Order S Q26621128 . . .

You are given a sorted array S[1, . . . , n] of n (distinct)numbers, i.e., the numbers in the array are arranged in increasingorder: S[1] < S[2] < · · · < S[n]. Give a recursivealgorithm to search for a given element (say x) in the array. If xis present in the array, the algorithm should return the index ofthe position where it is present, otherwise it should return 0.Your algorithm should take O(log n) comparisons. Give pseudocode ofyour algorithm and argue that your algorithm indeed takes O(log n)comparisons (in the worst case).

Expert Answer


Answer to Given Sorted Array S 1 N N Distinct Numbers E Numbers Array Arranged Increasing Order S Q26621128 . . .

OR