Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded dynamic fibonacci algorithm #523
Conversation
| */ | ||
| public class Fibonacci { | ||
|
|
||
| private static HashMap<Integer, Integer> fibonacciCache = new HashMap<>(); |
yejjuritesh
May 3, 2020
Instead of a HashMap, we can do this with constant space by using two variables.
Instead of a HashMap, we can do this with constant space by using two variables.
yejjuritesh
May 3, 2020
Also, An Array or ArrayList can be used instead of HashMap. Because the index of array can be assumed as the position of fibbonaci number :
index of Array- fibbonaci number
0 - 1
1 - 1
2 - 2
3 - 3
4 - 5
5 - 8
So, nth fibonacci number will be present at nth index of array.
Also, An Array or ArrayList can be used instead of HashMap. Because the index of array can be assumed as the position of fibbonaci number :
index of Array- fibbonaci number
0 - 1
1 - 1
2 - 2
3 - 3
4 - 5
5 - 8
So, nth fibonacci number will be present at nth index of array.
| * | ||
| * @return the nth fibonacci number. | ||
| */ | ||
| public int fibonacci(int n) { |
yejjuritesh
May 3, 2020
Instead of a recursive approach or top-down dynamic approach, A bottom-up approach will do the trick.
Instead of a recursive approach or top-down dynamic approach, A bottom-up approach will do the trick.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Due to the conversation with @varunu28 I now made a fibonacci algorithm that (hopefully) is dynamic programming