We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 602df1f commit 5510bb8Copy full SHA for 5510bb8
src/_Classics_/fibonacci/index.js
@@ -34,3 +34,24 @@ function fibonacciMemoized(index, cache) {
34
}
35
return cache[index];
36
37
+
38
+/**
39
+ * Using the bottom up approach, also known as tabular method
40
+ */
41
42
+function fibonacciTabular(n) {
43
+ const table = [0, 1];
44
45
+ for (let i = 2; i <= n; i += 1) {
46
+ table[i] = table[i - 1] + table[i - 2];
47
+ }
48
49
+ return table[n];
50
+}
51
52
+// const number = 50;
53
54
+// console.log(`Fib normal - ${fibonacci(number)}`);
55
+// console.log('--');
56
+// console.log(`Fib memo - ${fibonacciMemoized(number)}`);
57
+// console.log(`Fib table - ${fibonacciTabular(number)}`);
0 commit comments