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

Tribonacci Approach

In this lesson, Alvin explores the strategy to solving the following problem using dynamic programming:

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

The 0-th and 1-st numbers of the sequence are both 0.

The 2-nd number of the sequence is 1.

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

Solve this recursively.

tribonacci(0) # -> 0
tribonacci(1) # -> 0
tribonacci(2) # -> 1
tribonacci(5) # -> 4
tribonacci(7) # -> 13
tribonacci(14) # -> 927
tribonacci(20) # -> 35890

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/