• edited by
484 views
0 0 votes

How can we get this solution by solving this recurrence?

5:45 PM
(
$(2)=1$
$(1)=0$

If n is a power of 2 , then we can write $T(n)$ as:
\[
T(n)=2 T(n / 2)+2
\]

After solving above recursion, we get
\[
T(n)=3 / 2 n-2
\]

Thus, the approach does $3 / 2 n-2$ comparisons if $n$ is a power of 2 . And it does more than $3 / 2 n-2$ comparisons if $n$ is not a power of 2 .

METHOD 3 (Compare in Pairs)
If n is odd then initialize min and max as first element.

If $n$ is even then initialize min and max as minimum and maximum of the first tiwo elements respectively.

For rest of the elements, pick them in pairs and compare their

1 Answer

Position:
Show:

Related questions

3 3 votes
2 answers 2 answers
599
599 views
Rohan Mundhey asked Nov 10, 2016
599 views
$\Leftrightarrow=\{=$
2 2 votes
2 answers 2 answers
1.0k
1.0k views
Payal Rastogi asked Nov 15, 2015
1,013 views
17. The solution to the recurrence $\mathrm{T}\left(2^{\mathrm{k}}\right)=3 . \mathrm{T}\left(2^{\mathrm{k}-1}\right)+1$ with $\mathrm{T}(1)=1$ is:$\mathrm{O}(\mathrm{k})...
0 0 votes
1 1 answer
959
959 views
gate_forum asked Jan 13, 2019
959 views
O(n)O(Log n)O(Log log n)none
0 0 votes
1 1 answer
1.7k
1.7k views
syncronizing asked Sep 7, 2018
1,744 views
T(n) = T(root(n)) + n where n>=2Time complexity ?