Brief History of Fibonacci numbers and a fun fact about them !
The Fibonacci sequences were named after an Italian mathematician Leonardo Pisano or Fibonacci . He used the arithmetic series to represent a problem formed on a pair of breeding rabbits.
What are Fibonacci numbers anyways?
They are series of numbers in which each numbers are the sum of the two preceding numbers. For instance, 1,1,2,3,5,8 and so on.
Note: They start with either one or zero. Fibonacci sequences are denoted F (n), where n values are the first term in the sequence, the following equation obtains for n = 0, where the first two terms are defined as 0 and 1 by convention:
Code Time: Use different recursion methods to find the nth number of the Fibonacci sequences.
import java.util.HashMap;
public class HaiyluFibonacci {
private HashMap<Integer, Integer> map;
public HaiyluFibonacci() {
map = new HashMap<>();
}
public int findFibonacciValue(int number) {
if (number == 0 || number == 1) {
return number;
}
else if (map.containsKey(number)) {
return map.get(number);
}
else {
int fibonacciValue = findFibonacciValue(number — 2) + findFibonacciValue(number — 1);
map.put(number, fibonacciValue);
return fibonacciValue;
}
}
}
#Java # Fibonacci Numbers