Iteration vs. Recursion

Given relationship between problem/solution and subproblem/partial solution, we can proceed in forward direction, i.e. iteratively, or in backward direction, i.e. recursively.

Summation

$$\begin{eqnarray}
&&sum(\{~\}) &= 0 \\
&&sum(\{a_1,\dots,a_{n+1}\}) &= sum(\{a_1,\dots,a_n\})+a_{n+1}
\end{eqnarray}$$

Or

$$\begin{equation}
sum(\{a_1,\dots,a_n\})=\left\{
\begin{array}{ll}
0 & \text{if } n = 0 \\
sum(\{a_1,\dots,a_{n-1}\})+a_n & \text{if } n > 0
\end{array}
\right.
\end{equation}$$

Coding

???

You have no rights to post comments