Recursive function into non-recursive

2.5k Views Asked by At

I have to express $a_n$ in terms of $n$. How do I convert this recursive function into a non-recursive one? Is there any methodology to follow in order to do the same with any recursively defined function? Thanks.

$$a_n = \begin{cases} 0 & \text{if }n=1\\ a_{n-1}+n-1 & \text{if }n \ge 2 \end{cases} $$

So the results would be:

$$ a_1 = 0 \\ a_2 = 1 \\ a_3 = 3 \\ a_4 = 6 \\ a_5 = 10 \\ ... \\ $$

2

There are 2 best solutions below

3
On BEST ANSWER

OK, with the corrected recursion formula we get:

$$a_1=0\\ a_2=0+(2-1)=0+1\\ a_3=0+(2-1)+(3-1)=0+1+2\\ a_4=0+(2-1)+(3-1)+(4-1)=0+1+2+3\\\vdots\\ a_n=\sum_{k=0}^{n-1}k=\frac{n(n-1)}{2}$$

0
On

Sadly there isn't really a general method for doing this I believe but you can often try to break these problems into parts. The '$n$' term means that for each successive term we add on the term number, so by the $m$'th term this will have contributed $2+3+4+\ldots + m$. The -1 term means that (obviously) each time we take away another one. So what is the overall effect of these terms by the time we're at the $m$'th term?