Skip to content
GATEiit

GATE CSE 2017 Session 1 Q58: Worst-case probes to find the first 1 in a sorted 0/1 array of 31 elements

Syllabus topic: Searching, sorting and hashing

Question

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

Try it: numerical answer: type the value

Numerical answer. No negative marking.
Show answer and explanation

Answer: 5 (official GATE 2017 final answer key)

Concept used: Binary search for the 0/1 boundary; the number of possible boundary positions bounds the probes from below by ⌈log⁡2(outcomes)⌉.

Concept notes

Loading notes…

First step: Count how many possible positions the first 1 can have (including the case of no 1), and how much one probe can halve this.

Full step-by-step solution

Loading…

Answer from the official final answer key. Found a mistake? Use Report issue and we will fix it.

More questions on Searching, sorting and hashing

Every PYQ on this topic →

Share this question

WhatsAppDownload image

Source: official GATE 2017 Session 1 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key