True or False Time complexity questions

474 Views Asked by At

Here is my go at them and any help is appreciated:

If $f(n) = \Theta(n^2)$ and $g(n) = \Theta(n^2)$ then $(f - g)(n) = \Theta(n^2)$ where we define $(f-g)(n) = f(n) - g(n) \forall n$ TRUE?

If $f(n) = \Theta(n^2)$ and $g(n) = \Theta(n^2)$ then $(f * g)(n) = \Theta(n^4)$ where we define $(f*g)(n) = f(n) * g(n) \forall n$ TRUE?

If $f(n) = \Theta(n^2)$ and $g(n) = \Theta(n)$ then $(f + g)(n) = \Theta(n^3)$ where we define $(f+g)(n) = f(n) + g(n) \forall n$ FALSE?

If $T(n) = T(n-1) + n^2$ with $T(1) = 1$. Then $T(n) = \Theta(n^3)$. FALSE?

If $T(n) = 2T(n/2) + n$ with $T(1) = 1$. Then $T(n) = \Theta(n^3)$. TRUE?

1

There are 1 best solutions below

0
On

1) Let $f(n) = g(n) = n^{2}$. Clearly both $f, g \in \Theta(n^{2})$. However, $(f-g)(n) = 0$. So that's in $\Theta(1)$.

2) Correct.

3) Correct.

4) We really have $T(n) = T(1) + \sum_{i=2}^{n} i^{2}$. We note that the sum of the first $n$ squares is a cubic, so $T(n) = \Theta(n^{3})$.

5) Apply the Master Theorem: $T(n) = aT(n/b) + n$. Here, $a = b = 2$. Let $c = log_{b}(a) = 1$. So clearly, $n = \Theta(n^{c}) = \Theta(n)$. So we use case (2) to get $T(n) = \Theta(n log(n))$