I need to calculate the complexity of func5, depending on variables $n, m$.
func4 is a function whose complexity is $\Theta(n+m)$
void func5(int a[], int n, int m, int b[])
{
if (n==0) { return; }
*b = func4(a,n,m);
func5(a+1,n-1,m,b+1);
}
I get an expression which looks like:
$$C_1*n + C_2*(nm+n^2) - C_2(1+2+3+..n)$$
$C_1$ is the operations done in each iteration of func5,
$C_2$ is the operations done in each call to func4,
and the substraction comes since func4 is receiving each time a smaller $n$ by one.
The answer says that complexity is $\Theta(n*m+n^2)$ but I don't understand how to find the constants leading to Big-Theta notation.
Thanks.