in Algorithms edited by
790 views
0 votes
0 votes

​​​​​Let $F(n)$ denote the maximum number of comparisons made while searching for an entry in a sorted array of size $n$ using binary search.

Which ONE of the following options is TRUE?

  1. $F(n)=F(\lfloor n / 2\rfloor)+1$
  2. $F(n)=F(\lfloor n / 2\rfloor)+F(\lceil n / 2\rceil)$
  3. $F(n)=F(\lfloor n / 2\rfloor)$
  4. $F(n)=F(n-1)+1$

in Algorithms edited by
by
790 views

1 Answer

3 votes
3 votes
In binary search, at each step, you compare the target element with the middle element of the array. Based on the comparison result, you recursively search either the left or the right half of the array.

Let's denote \( F(n) \) as the maximum number of comparisons made while searching for an entry in a sorted array of size \( n \) using binary search.

For an array of size \( n \):

- At each step, you make 1 comparison to check if the target is equal to the middle element.

- Then, you either search the left half or the right half of the array.

- So, the maximum number of comparisons for an array of size \( n \) is \( F(n) = 1 + F\left(\left\lfloor\frac{n}{2}\right\rfloor\right) \).

So, the correct option is:
A. \( F(n) = F\left(\left\lfloor\frac{n}{2}\right\rfloor\right) + 1 \)

Related questions