See Our team

Wondering how we keep quality?

Got unsolved questions?

Ask Questions

Engineering
GATE
CBSE
NCERT
Psychology
English
Computer
Constitution
Astrology
Yoga
Economics
Physics
Biology
Electronics
Microprocessor
Career
Interview
Anatomy
Botany

## 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...

## Use Me ?