From the course: Fundamentals of Dynamic Programming
Unlock this course with a free trial
Join today to access over 22,500 courses taught by industry experts.
The Fibonacci sequence - Python Tutorial
From the course: Fundamentals of Dynamic Programming
The Fibonacci sequence
- Classic introductory problem in dynamic programming is computing the Fibonacci Sequence. The Fibonacci sequence , is a sequence in numbers starting with one followed by one. The next element is the sum of the two previous elements. For example, one plus one is two, one plus two is three, two plus three is five. And so on . One way to describe the sequence is with the Recursive formula. Assuming we index the sequence starting with zero, we have F of zero is one and F of one is a one. After that, the Fibonacci number with index N F of N is simply the sum of F of N minus one and F of N minus two. This formulation is already close to a Python implementation. So let's take a look while real world code would do some error handling, I'm keeping it simple. The input to the fifth function is the index of the number to compute. There are two base cases for when the input is zero or one, and the remaining case just…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.