Machine-translated by Google. Questions are authored in English.
Top

Discussion

Consider the following recurrence relation:

\(T(n) = 2T(n - 1) + n2^{n}\) for \(n \gt 0\), \(T(0) = 1\).

Which ONE of the following options is CORRECT?

  • A.\(T(n) = \Theta(n^{2}2^{n})\)
  • B.\(T(n) = \Theta(n2^{n})\)
  • C.\(T(n) = \Theta((\log n)^{2}\,2^{n})\)
  • D.\(T(n) = \Theta(4^{n})\)

Answer: A

The solution is \(T(n) = \Theta(n^{2}2^{n})\).

Divide both sides by \(2^{n}\) and set \(S(n) = T(n)/2^{n}\):

\[ \begin{aligned} \frac{T(n)}{2^{n}} &= \frac{T(n-1)}{2^{n-1}} + n \\ S(n) &= S(n-1) + n \\ S(n) &= 1 + \frac{n(n+1)}{2} \end{aligned} \]

using \(S(0) = T(0) = 1\). So \(T(n) = 2^{n}\left(1 + n(n+1)/2\right) = \Theta(n^{2}2^{n})\).

\(\Theta(n2^{n})\) treats the added term as if it did not accumulate over the n levels, \((\log n)^{2}2^{n}\) grows too slowly, and \(4^{n}\) is far too fast, since the recurrence only doubles at each step.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.