retagged by
11,933 views
14 votes
14 votes

What is the worst-case number of arithmetic operations performed by recursive binary search on a sorted array of size $n$?

  1. $\Theta ( \sqrt{n})$
  2. $\Theta (\log _2(n))$
  3. $\Theta(n^2)$
  4. $\Theta(n)$
retagged by

4 Answers

Best answer
16 votes
16 votes

Worst-case number of arithmetic operations performed by recursive binary search on a sorted array is given by the following recurrence relation:

$T(n) = T(\frac{n}{2}) + \Theta(1) $

$\text{for }~T(n) = aT(\frac{n}{b}) + f(n), \\ a\geq 1, b > 1$

$\text{Case 2 of master theorem says,}$

$\text{if}~~f(n) = \Theta(n^{\log_ba}) \\ \text{then}~~T(n) = \Theta(n^{\log_ba}\cdot \log(n)) $

$\text{Here, }n^{\log_b(a)} = n^{\log_2(1)} = n^0 = 1\\ \Rightarrow f(n) = \Theta(n^{\log_b(a)}) $

$\text{Hence, we can conclude that }T(n) = \Theta(1\cdot \log_2(n)) = \Theta(\log_2(n))$

B is correct

selected by
1 votes
1 votes

option B 

Binary search which can be recursively applied on sorted data items 

has Worst case and avg case time complexity O(log n) and  best case O(1)  or it is also correct to write as Θ(logn)

and Θ(1) since worst case /avg case /best case are both upper bound and lower bound by  log n / log n / 1

https://en.wikipedia.org/wiki/Binary_search_algorithm

No of arithmetic operations will  be Θ(logn) in worst case  as every comparison need 2 operation + and / by 2

edited by
0 votes
0 votes

The operation has to be performed on one element in the sorted binary tree. Thus the recursive function becomes-

T(n)=  T(n/2) + 1   where 1 represents the operation performed. So by masters theorem  Θ(log2(n)). Hence option B

Answer:

Related questions

14 votes
14 votes
4 answers
1
Arjun asked Feb 18, 2021
8,881 views
​​​​​Let $H$ be a binary min-heap consisting of $n$ elements implemented as an array. What is the worst case time complexity of an optimal algorithm to find the...
11 votes
11 votes
4 answers
3