Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Software engineer here; I've written a little program which demonstrates that for the following function:

$$f(n+1) = f(n)+n+1$$

starting with

$$f(0)=0$$

the following is true:

$$\lim_{n\to \infty}\left(f(n)\right) = \frac{n^2}{2}$$

and therefore the Big-O notation which best describes the function is $O(n^2)$. I have no idea how to prove it formally, though. Can anyone help?

share|improve this question
    
Also, if anyone would like to help tag this properly, that would be splendid. :-) –  bythescruff Dec 10 '12 at 12:30
    
$\lim_{n\to \infty} f(n) = \infty$, not $\frac{n^2}{2}$. –  user1551 Dec 10 '12 at 12:47
    
@user1551 True; I didn't quite know how to say, "As n gets bigger, values of f(n) get closer to values of (n^2)/2" formally. :-) –  bythescruff Dec 10 '12 at 13:14
    
@bythescruff In the future you could use the asymptotic notation: $f\sim g$ if $f/g \to 1.$ So here you could have wrote $f\sim n^2/2.$ –  Ragib Zaman Dec 10 '12 at 13:22
    
@bythescruff "As n gets bigger, values of $f(n)$ get closer to values of $n^2/2$". This is formal enough, isn't it? ;-D By the way, this formal statement is false too. $f(n)$ does not get closer to $n^2/2$ when $n$ is getting large. In fact, $f(n)$ departs from $n^2/2$ more and more when $n\rightarrow\infty$. The ratio $f(n)/(n^2/2)$ does approach 1, though. As pointed out by Ragib Zaman, this is usually written as $f\sim n^2/2$. –  user1551 Dec 10 '12 at 13:28

1 Answer 1

up vote 8 down vote accepted

We can write the relation as $f(n+1) - f(n ) = n+1.$ Thus, $$ f(n) = (f(n) - f(n-1) ) + (f(n-1) - f(n-2) ) + \cdots + (f(1) - f(0) ) + f(0) $$

$$ = n+ (n-1) + (n-2) + \cdots +1 = \frac{n(n+1)}{2}.$$

share|improve this answer
    
Thanks for your answer, but embarrassingly enough, I'm having trouble working out how you get from line 1 to line 2. Can you break it down a little more for me please? It's been a long time since my physics degree... :-) –  bythescruff Dec 11 '12 at 6:14
    
@bythescruff In the first line, we express $f(n)$ as a sum of many terms of the form $f(i) - f(i-1).$ By the relation, we know that these $f(i)-f(i-1)=i$, and putting $i$ in place of the $f(i)-f(i-1)$ gives the second line. –  Ragib Zaman Dec 11 '12 at 12:45
    
Aha, penny dropped now. Thanks. –  bythescruff Dec 12 '12 at 13:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.