Profile picture
Alvin ZablanFounder at Structy and React Formula | ex-Google

Fibonacci Approach

In this lesson, Alvin explains the fundamentals of dynamic programming by applying dynamic programming to fibonacci:

Write a function fib that takes in a number argument, n, and returns the n-th number of the Fibonacci sequence.

The 0-th number of the sequence is 0.

The 1-st number of the sequence is 1.

To generate further numbers of the sequence, calculate the sum of previous two numbers.

Solve this recursively.

fib(0); # -> 0
fib(1); # -> 1
fib(2); # -> 1
fib(3); # -> 2
fib(4); # -> 3
fib(5); # -> 5
fib(35); # -> 9227465

If you need additional support taking these DSA skills and actually applying them, take Alvin's complete data structures and algorithms course on Structy. You can try out the concepts yourself in their interactive code editor and learn advanced DSA patterns like stack exhaustive recursion.

Use this link to get 20% off the entire Structy DSA learning experience.

Follow Alvin on LinkedIn: https://www.linkedin.com/in/alvin-zablan-b73a92117/