Q57 Let A be an array of 31 numbers consisting of a sequence of 0s followed by a sequence of 1s The problem is to find the smallest index i such that Ai is 1 by probing the minimum number of locations in A The worst case number of probes performed by an optimal algorithm is gate computer science 2017
The Eduladder is a community of students, teachers, and programmers just interested to make you pass any exams. So we solve previous year question papers for you.
See Our team
Wondering how we keep quality?
Got unsolved questions?

Hey! Want to work with us? Our youtube channel See our Jd Want to apply? Do it today

### Use Me  ?

New searches
GATE-Computer-Science-Engineering-2017-->View question

## Q.57) Let A be an array of 31 numbers consisting of a sequence of 0’s followed by a sequence of 1’s. The problem is to find the smallest index i such that A[i] is 1 by probing the minimum number of locations in A. The worst case number of probes performed by an optimal algorithm is________. -gate computer science 2017

A) 2
B) 3
C) 4
D) 5

By:satyashiromani

Taged users:

Likes:
|satyashiromani

Dislikes:
Be first to dislike this question

D) 5

Explanation:
The best way to solve such a problem is by using Binary Search. Search the sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Find mid element
Is mid = 1 ?
Is mid >1?(not possible here)
Is mid < 1 ?
Proceed accordingly, Worst case of this problem will be 1 at the end of the array i.e 00000.....1 OR 1.......0000. It will take log n time worst case. n=31, Hence log 231 = 5. Therefore, option D is correct.

This explanation is contributed by Deepak Raj

deepuckraj

Likes:
Be first to like this answer

Dislikes:
Be first to dislike this answer