in Algorithms retagged by
11,788 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)$
in Algorithms retagged by
by
11.8k views

4 Comments

Option B?
3
3
(B) logn offcourse
0
0
Correct option is B .

As avg case and worst case tc for BS is O(log n).
1
1
Every binary search pass will perform 2 operations. "+" & "/ by 2". so no. of arithmatic operations = 2*logn which is Θ(logn)
5
5

4 Answers

16 votes
16 votes
Best answer

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

4 Comments

@Nikhil_dhama what if O(logn) was also given in option ??

0
0

@abir_banerjee Then also ϴ( log n ) should be correct as its more tighter bound than O( log n )

0
0

we have to select the exact one then not the upper-bound.

0
0
1 vote
1 vote

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

3 Comments

edited by
What are arithmetic operations performed in recursive binary search?
0
0
They will also be same as every comparison need two operations (addition and division) mid = beg+end/2
1
1

Computation of mid element requires arithmetic operations:

Lower Mid: [ start + (end-start)/2 ] or Upper mid: [ start + (end – start +1)/2 ]

1
1
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

0 votes
0 votes

(B.) Binary Search WC T.c. Is- O(log(n))

Answer:

Related questions