Table of Contents
Fibonacci Series in Data Structures and Algorithms is easier to understand when the core ideas are paired with practical examples. The sections below explain the topic clearly, highlight useful steps, and point out details that can prevent common errors.
What is the Fibonacci sequence?
The Fibonacci sequence creates numbers by adding two numbers in front. Fibonacci series start from two numbers: F0 & F1. The initial value of F0 & F1 may be 0, 1 or 1, 1, respectively.
The condition of the Fibonacci sequence is:
F n = F n-1 + F n-2
Example of a Fibonacci sequence:
F 8 = 0 1 1 2 3 5 8 13
Example of another Fibonacci sequence:
F 8 = 1 1 2 3 5 8 13 21
Below is an illustration of the Fibonacci sequence on:

The algorithm uses a loop for the Fibonacci sequence
First, our algorithm will use the loop to create the Fibonacci sequence:
B ? t ?? u gi ? i thu ? t Fibonacci ( n ) khai b á o f 0 , f 1 , fib , loop Thi ? t l ? p f 0 l à 0 Thi ? t l ? p f 1 l à 1 hi ? n th ? f 0 , f 1 for loop ? 1 t ? i n fib ? f 0 + f 1 f 0 ? f 1 f 1 ? fib hi ? n th ? d ã y fib k ? t th ú c for K ? t th ú c gi ? i thu ? t
The algorithm uses recursion for the Fibonacci sequence
Next, based on recursion we will design the algorithm for the Fibonacci sequence as follows:
B ? t ?? u gi ? i thu ? t Fibonacci ( n ) khai b á o f 0 , f 1 , fib , loop Thi ? t l ? p f 0 l à 0 Thi ? t l ? p f 1 l à 1 hi ? n th ? f 0 , f 1 for loop ? 1 t ? i n fib ? f 0 + f 1 f 0 ? f 1 f 1 ? fib hi ? n th ? d ã y fib k ? t th ú c for K ? t th ú c gi ? i thu ? t
FAQ
What is the Fibonacci sequence?
The Fibonacci sequence creates numbers by adding two numbers in front. Fibonacci series start from two numbers: F0 & F1. The initial value of F0 & F1 may be 0, 1 or 1, 1, respectively.
What should you know about the algorithm uses a loop for the Fibonacci sequence?
First, our algorithm will use the loop to create the Fibonacci sequence:
What should you know about the algorithm uses recursion for the Fibonacci sequence?
Next, based on recursion we will design the algorithm for the Fibonacci sequence as follows:
Reader Comments 0
Sign in with email or Google to join the discussion.