GATE CSE 2017 Session 1 Q58: Worst-case probes to find the first 1 in a sorted 0/1 array of 31 elements
- Algorithms
- 2 marks
- NAT
- No negative marking
Syllabus topic: Searching, sorting and hashing
Question
Let 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 such that is 1 by probing the minimum number of locations in . The worst case number of probes performed by an optimal algorithm is ______.
Try it: numerical answer: type the value
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 .
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
Source: official GATE 2017 Session 1 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key
More Algorithms PYQs
- 2026 Session 1 · Q17Solve nested recurrences T1 = 4T1(n/2) + T2, T2 = 5T2(n/4) + log n
- 2026 Session 1 · Q41Shortest paths with at most k edges: two statements
- 2026 Session 1 · Q47Condition forcing a vertex into every minimum vertex cover
- 2026 Session 1 · Q49Cycle and cut properties of MSTs with distinct weights
- 2026 Session 1 · Q50Impossible DFS discovery/finish orderings for a DAG edge
- 2026 Session 1 · Q55Properties of 2-colorable (bipartite) graphs