From 6aaa663688bafd6626ea63243a77e9754b799c10 Mon Sep 17 00:00:00 2001 From: Lee Southerst Date: Thu, 28 Sep 2017 12:59:16 -0400 Subject: [PATCH] Added bottom up DP implementation of Fibonacci --- Algorithms/dynamic_programming/fibonacci.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Algorithms/dynamic_programming/fibonacci.js diff --git a/Algorithms/dynamic_programming/fibonacci.js b/Algorithms/dynamic_programming/fibonacci.js new file mode 100644 index 000000000..0595afead --- /dev/null +++ b/Algorithms/dynamic_programming/fibonacci.js @@ -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);