The best programs are written so that computing machines can perform them quickly and so that human beings can understand them clearly. A programmer is ideally an essayist who works with traditional aesthetic and literary forms as well as mathematical concepts, to communicate the way that an algorithm works and to convince a reader that the results will be correct. ― Donald E. Knuth

# Algorithms

## Dynamic Programming

Problem :-
Find the nth term of fibonacci series.

Solution :-
In a Fibonacci series, every term is equal to the sum of previous two terms :
0 , 1 , 1 , 2 , 3 , 5 , 8 ,13 , 21 , 34 , 55 , .....
Mathematically, fib ( n ) = fib ( n - 1 ) + fib ( n - 2 ) with fib ( 0 ) = 0 and fib ( 1 ) = 1. This is the structure of an optimal solution defined recursively.
Recursive function to find the nth term is show below. This is not an efficient solution since there will be repeated computation for some sub-problems. Dynamic programming approach maintains an array fib of size n + 1 in which each fibonacci term starting from 0th term is stored. For e.g, fib [ 2 ] stores the 2nd term of fibonacci series. Finally, fib [ n ] gives the nth term.
See the function getFibTerm2 ( int n ) below for the dynamic programming solution.