edited by
3,491 views
3 3 votes
CAN SOMEONE SOLVE THE NUMBER OF COMPARISIONS FOR COMPUTING MIN AND MAX IN AN ARRAY USING DIVIDE N CONQUER??

RECURRENCE RELATION IS

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

IT SHOULD COME TO $ \frac{3*n}{2} - 2 $

??

1 Answer

Best answer
7 7 votes
To understand, first you have to understand this

$ \sum_{i=0}^{n} 2^i = 2^{n+1} -1 $
or $ \sum_{i=1}^{n} 2^i = 2^{n+1} -2 $

Now Come to your recurrence, let $ n = 2^k $

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

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

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

      $  = 2^3 T(\frac{n}{ 2^3 }) + 2^3 + 2^2 + 2 $

      $  = 2^4 T(\frac{n}{ 2^4 }) + 2^4 + 2^3 + 2^2 + 2 $

      $ --------------------------------- $

      $ --------------------------------- $

      $  = 2^{k-1} T(\frac{n}{ 2^{k-1} }) +2^{k-1} + ------------ +  2^3 + 2^2 + 2 $

      $  = 2^{k-1} T(\frac{2^k}{ 2^{k-1} }) +2^{k-1} + ------------ +  2^3 + 2^2 + 2 $,  Since $ n = 2^k $

      $  = 2^{k-1} T(2) +2^{k-1} + ------------ +  2^3 + 2^2 + 2 $

      $  = 2^{k-1} * 1 +2^{k-1} + ------------ +  2^3 + 2^2 + 2 $, Since $ T(2) = 1 $

      $  = 2^{k-1} +2^{k-1} + ------------ +  2^3 + 2^2 + 2 $

      $  = 2^{k-1} + \sum_{i=1}^{i = (k-1)} 2^i $

      $  = 2^{k-1} +2^{k} - 2  $

      $  = \frac{n}{2} + n - 2  $ , Since $ n = 2^k $ ==> $ k = log 2 $

$ T(n) = \frac{3*n}{2} - 2 $

Hence Solved.
selected by
Position:
Show:

Related questions

0 0 votes
1 answers 1 answer
1.2k
1.2k views
ajit asked Sep 7, 2015
1,169 views
given a sorted array of distinct integers A[1........n], you want to find out whether there is an index i for which A[i]=i.if this problem is solved using divide and conq...
5 5 votes
1 1 answer
172
172 views
GO Classes asked Aug 5
172 views
Suppose $n$ elements are divided into groups of $r$ elements. The median of each group is found, and the median of these group medians is used as the selection pivot.For ...
4 4 votes
1 1 answer
176
176 views
GO Classes asked Aug 4
176 views
There are $n$ cities, and exactly $k$ of them are contaminated. A test on any subset tells whether at least one contaminated city is present in that subset.A divide-and-c...
1 1 vote
1 answers 1 answer
1.0k
1.0k views
Emankashyap asked Apr 30, 2024
1,049 views
In quick sort, n numbers the (n/10)th element is selected as pivot using n^2 sortimng time complexity what will be the time complexity of quick sort is.....a)O(nlogn)b)O(...