edited by
18,111 views
47 votes
47 votes

The recurrence equation
$ T(1) = 1$
$T(n) = 2T(n-1) + n, n \geq 2$

evaluates to

  1. $2^{n+1} - n - 2$
  2. $2^n - n$
  3. $2^{n+1} - 2n - 2$
  4. $2^n + n $
edited by

7 Answers

Best answer
65 votes
65 votes
$T(n) = 2T(n-1) +n, n \geqslant 2 , T(1) = 1$

$  T(n)    = n + 2(n-1) + 2^2 (n-2) + \dots + 2^{(n-1)}(n -(n-1))$

           $=n( 1 + 2 + \dots + 2^{n-1}) - (1.2 + 2.2^{2} +3.2^{3}+\dots+ (n-1).2^{n-1})$

           $=n(2^n-1) -(n.2^n-2^{n+1}+2)$

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

Correct Answer: $A$
edited by
106 votes
106 votes
T(1) = 1

T(2) = 4

T(3) = 11

T(4) = 26

T(5) = 57

T(6) = 120

T(7) = 247

So, $$T(n) = 2^{n+1} - n - 2$$
30 votes
30 votes
Given that T(1) =1 //OMG here itself Option C & D fails now check A & B

T(2)=2T(1)+n=2+2=4 //Option B evaluates to 2 so it is wrong

Hence option A is ans.
12 votes
12 votes

solution .

Answer:

Related questions

19.8k
views
6 answers
31 votes
Kathleen asked Sep 18, 2014
19,753 views
The time complexity of the following C function is (assume $n > 0$)int recursive (int n) { if(n == 1) return (1); else return (recursive (n-1) + recursive (n-1)); }$O(n)$O(n \log n)$O(n^2)$O(2^n)$
20.8k
views
13 answers
66 votes
Kathleen asked Sep 18, 2014
20,788 views
Let $A[1,\ldots,n]$ be an array storing a bit ($1$ or $0$) at each location, and $f(m)$ is a function whose time complexity is $\Theta(m)$. Consider the following program ... (n^2)$\Omega (n\log n) \text{ and } O(n^2)$\Theta(n)$o(n)$
16.3k
views
3 answers
37 votes
Kathleen asked Sep 18, 2014
16,337 views
Suppose we run Dijkstra's single source shortest path algorithm on the following edge-weighted directed graph with vertex $P$ as the source.In what order do the nodes get included into the set of ... $P,Q,T,R,U,S$
14.7k
views
6 answers
33 votes
Kathleen asked Sep 18, 2014
14,717 views
What does the following algorithm approximate? (Assume $m > 1, \epsilon >0$).x = m; y = 1; While (x-y > ϵ) { x = (x+y)/2; y = m/x; } print(x);$\log \, m$m^2$m^{\frac{1}{2}}$m^{\frac{1}{3}}$