Quick Running Time Question

62 Views Asked by At

I have a quick question about some running time stuff. In my algorithm I run merge sort twice, then loop $n$ times. If this is the case, does this make sense?

$\Theta(nlogn+nlogn+n) = \Theta(nlogn)$.

I am a bit uncertain about the $\Theta(nlogn+n) = \Theta(nlogn)$ aspect but fairly certain this is a true statement.

Edit : Should add that only constant operations occur within the loop.

2

There are 2 best solutions below

1
On BEST ANSWER

Yes, it's true. Since $n \log{n} > n$, complexity grows (is dominated by) $n \log{n}$.

0
On

Upper bound: $$ f(n)=n \log n +n \log n +n \leq 3 n \log n= O(n \log n) $$ Lower bound: $$ f(n) \geq 2 n \log n =\Omega (n \log n) $$ hence $f(n)=\Theta(n \log n)$