mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 01:18:23 +08:00
Added bottom up DP implementation of Fibonacci
This commit is contained in:
14
Algorithms/dynamic_programming/fibonacci.js
Normal file
14
Algorithms/dynamic_programming/fibonacci.js
Normal file
@ -0,0 +1,14 @@
|
||||
|
||||
function fib(n) {
|
||||
var table = [];
|
||||
table.push(1);
|
||||
table.push(1);
|
||||
for (var i = 2; i < n; ++i) {
|
||||
table.push(table[i - 1] + table[i - 2]);
|
||||
}
|
||||
console.log("The %dth fibonacci number is %d", n, table[n - 1]);
|
||||
}
|
||||
|
||||
fib(200);
|
||||
fib(5);
|
||||
fib(10);
|
Reference in New Issue
Block a user