Find the fibonacci of f(n) JavaScript

Abhijit chakra
Oct 13, 2020

--

Here we will find the fibonacci of a number n f(n) = f(n-1) + f(n-2) while n>2 using dynamic programming top down (memorization) technique

/**

* find the fibonacci of a number using dynamic programming

* Top Down Appach (memorisation)

*/

function findFib(n,cache){

cache = []

if(n<2){

return n

}

if(!cache[n]){

return cache[n]= findFib(n-1,cache)+findFib(n-2,cache)

}

return cache[n]

}

console.log(findFib(6))

The best book for cracking coding interview in my experience , available on amazon, link is below book

The best book for cracking coding interview in my experience , available on amazon, link is below book

https://amzn.to/3cFjyGy

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response