1
$\begingroup$

I have an algorithm which for two input parameters $m,n$ has a complexity of:

$$\sum_{i=1}^n m^n$$

this gives me the closed form of geometric series:

$$\frac{m(m^n-1)}{m-1}$$

Is it correct if I write that my algorithm has a complexity of $O(\frac{m(m^n-1)}{m-1})$, or could this be further simplified?

Note that $m \geq 1, n \geq 1$.

  • 0
    What range of values can $m$ be?2017-02-22
  • 0
    $m$ is always greater or equal to 1, and so is $n$ sorry forgot to add that. There is no upper bound on $m$2017-02-22
  • 2
    @3.14 Note that if $m = 1$ the formula for the geometric series does not hold. Instead, the sum is just $n$.2017-02-22
  • 0
    Clearly this whole thing is $O(m^n)$.2017-02-22

3 Answers 3

0

$\frac{m(m^n-1)}{m-1} \leq 2(m^n-1)$ for sufficiently large $m$, since $\lim_{m \to \infty} \frac{m}{m-1}=1$ implies that there are only finitely many terms greater than $2$.

Hence, we can just write

$\frac{m(m^n-1)}{m-1}=O(m^n-1)=O(m^n)$.

In the case that $m=1$, the sum is just $1+...+1=n$.

  • 0
    This $-1$ is of no use.2017-02-22
  • 0
    @YvesDaoust there were a few problems, I should be less hasty with my answers.2017-02-22
  • 0
    Thanks for the explanation :)2017-02-22
2

If you know the exact expression

$$\frac{m(m^n-1)}{m-1}$$ you can just keep it like it is.

Or, after dropping the two neglectible $-1$s,

$$\frac{m(m^n-1)}{m-1}=O(m^n).$$

As pointed by others, the expression reduces to $n$ when $m=1$. You can account for this by the notation

$$O(m^n+n).$$

  • 0
    Thanks for explanation, makes sense.2017-02-22
2

For any $m,n\geq 1$, we have $\sum_{i=1}^n m^n = n \cdot m^n$. Note that there is no $i$ in any term of the sum.

  • 0
    @3.14 Isn't there a typo in your formula ?2017-02-22
  • 0
    @YvesDaoust No there is no typo, there are only two input parameters: $m ,n$.2017-02-22
  • 0
    @3.14 Then my downvote for the wrong summation result, which lead me astray and needs to be fixed.2017-02-22
  • 0
    @YvesDaoust This formula shown here does not give the right result, lets assume that $m=4$, and $n=2$, the end result should be 20 (that is $4^1 + 4^2=20$), and not 32 (according to the formula here: $2 * 4^2=32$)2017-02-22
  • 0
    Equation in this post is wrong, as the powers of terms are in increasing order up to n, which are not accounted here!2017-02-22
  • 0
    @3.14 Shame on you, I already pinpointed your typo, which you just denied. $4^2+4^2=32$.2017-02-22
  • 0
    @YvesDaoust you got me totally confused, I don't get it where is that typo? The equation here is incorrect as it should be as I stated above i.e., $4^1+4^2=20$, and not 32.2017-02-22
  • 0
    @3.14: this is explained in this answer by Anonymous. Please read what people write.2017-02-22