GateAI
Searching, Sorting and Hashing

GATE CSE 2017 Set 1 · Q48

NAT2 marksMedium

Time

Let AA 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 ii such that A[i]A[i] is 1 by probing the minimum number of locations in AA. The worst case number of probes performed by an optimal algorithm is ________.

Your answerNumerical answer

Enter a value to check

Solution

Step-by-step verified solution

Official answer: 5 (±0)

Searching, Sorting and Hashing

The array AA of size n=31n = 31 is sorted in non-decreasing order (00s followed by 11s).

The number of zeros in the array can range from 00 to 3131. Therefore, there are 31+1=3231 + 1 = 32 possible configurations for the index of the first occurrence of 11 (including the case where there is no 11).

Each probe (comparison) at an index tests whether the value is 00 or 11, which gives a binary outcome and partitions the remaining search space into two parts.

By information theory, any comparison-based algorithm represented by a binary decision tree with KK possible outcomes requires at least ⌈log⁡2K⌉\lceil \log_2 K \rceil probes in the worst case:

Worst-case probes=⌈log⁡2(32)⌉=5\text{Worst-case probes} = \lceil \log_2(32) \rceil = 5

An optimal binary search algorithm can always find the transition point in at most 55 probes.

Thus, the worst-case number of probes is 5 [cite: 2].

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Searching, Sorting and Hashing previous year question is Q48 of the GATE CSE 2017 Set 1 paper. Find more GATE CSE PYQs on Searching, Sorting and Hashing in Algorithms, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Searching, Sorting and Hashing PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Searching, Sorting and Hashing in GATE CSE

Searching, Sorting and Hashing has 27 GATE CSE PYQs across 20 papers from 2012 to 2026. 4 of them are 2-mark NAT questions like this one, and it is the only one in GATE CSE 2017 Set 1.

How GATE tests Searching, Sorting and Hashing

More from GATE CSE 2017 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2017 Set 1 · Q48 · NAT

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 …

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.