in Algorithms retagged by
1,124 views
1 vote
1 vote

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

  1. $2$
  2. $4$
  3. $3$
  4. $5$
in Algorithms retagged by
by
1.1k views

1 comment

0
0

3 Answers

2 votes
2 votes
If we apply binary search to find first occurrence of 1 in the list, it will give smallest index i.

In this array, sequence of 0's is followed by sequence of 1's so it is sorted. So we can apply binary search directly.

Number of probes performed = ceil(log31 base2) = 5

So, correct answer is D.
1 vote
1 vote
Option D is correct
1 vote
1 vote
OPTION

D

 

SIMPLY APPLY BINARY SEARCH
Answer:

Related questions