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?

Ask 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:
|satyashiromani|Msshikhil|Samira|aksingh1818|vivek25|vaishnavi-Deshpande|soumya|amrita98|sonam||tarun101|Umang|Divyanshu-Changkakoti|tanya|thegdx|ThreeRed|arunsivag|preethi|shilpasri|varsshita|sahajajnana|saru|lakshmi|navyasn|kavana|Siddharth|rythil|Athul3480|SathyaKrishna|Ankur-kumar

Likes:
|satyashiromani

Dislikes:
Be first to dislike this question

Talk about thisDelete|Like|Dislike|


Answers

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
Talk about this|Once you have earned teacher badge you can edit this questionDelete|Like|Dislike|
------------------------------------

Can you help us to add better answer here? Please see this

Loading...


Not the answer you're looking for? Browse other questions from this Question paper or ask your own question.

Join eduladder!