MCPcopy Index your code
hub / github.com/TheAlgorithms/JavaScript / FibonacciDpWithoutRecursion

Function FibonacciDpWithoutRecursion

Maths/Fibonacci.js:80–90  ·  view source on GitHub ↗
(num)

Source from the content-addressed store, hash-verified

78// @Satzyakiz
79
80const FibonacciDpWithoutRecursion = (num) => {
81 const isNeg = num < 0
82 if (isNeg) num *= -1
83 const table = [0]
84 table.push(1)
85 table.push(isNeg ? -1 : 1)
86 for (let i = 2; i < num; ++i) {
87 table.push(isNeg ? table[i - 1] - table[i] : table[i] + table[i - 1])
88 }
89 return table
90}
91
92// Using Matrix exponentiation to find n-th fibonacci in O(log n) time
93

Callers 1

Fibonacci.test.jsFile · 0.90

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected