Fibonacci series in Data Structures and Algorithms

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:

Fibonacci series in Data Structures and Algorithms Picture 1

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 

According to Tutorialspoint

Previous article: Problem of Hanoi Tower (Tower of Hanoi)

Next article: assert.h in C

4.5 ★ | 2 Vote

May be interested

  • Alignment algorithm (Merge Sort)Alignment algorithm (Merge Sort)
    mixing (merge sort) is an arrangement algorithm based on the divide and conquer algorithm. with the worst case time complexity of Ο (n log n), this is one of the algorithms that deserves the most attention.
  • How to Become a Computer ScientistHow to Become a Computer Scientist
    being a computer scientist is not about programming; it is about the study of algorithms (a series of steps, understood by someone or something, in order to complete a task in a given number of steps). many computer scientists don't...
  • How are Facebook and Google using algorithms to predict your thoughts?How are Facebook and Google using algorithms to predict your thoughts?
    postings, information filled with ads always follow you in any corner of the internet in general and on social networking sites in particular. in particular, this advertising information is sometimes so relevant that it makes you think companies like facebook and google own some supernatural power that can read their thoughts.
  • How to rename data series in Excel chartHow to rename data series in Excel chart
    data series in excel is a collection of data displayed in a row or column shown in a chart or graph. and during data processing there will be times when you need to change the name of the data series. in the chart.
  • WhatsApp will test new algorithms for Status sort featureWhatsApp will test new algorithms for Status sort feature
    whatsapp is planning an experiment that could lead to a major change to one of the most popular features on its platform.
  • What is algorithm?What is algorithm?
    algorithms (also known as algorithms - english is algorithms) is a finite set of instructions to be executed in a certain order to get the desired result. in general, the algorithm is independent of programming languages, ie an algorithm can be deployed in many different programming languages.
  • DuraBook D14 E-Series protects data safetyDuraBook D14 E-Series protects data safety
    gammatech's durabook d14 e-series laptop features a storage capacity of up to 1tb and data protection mode options through raid setup
  • New algorithms to increase the accuracy of CAPTCHANew algorithms to increase the accuracy of CAPTCHA
    the new algorithm system has been developed to increase the accuracy of google service usage, against google machines and fraudulent computer programs.
  • Array (Array) in C / C ++Array (Array) in C / C ++
    c / c ++ programming language provides data structures called arrays, stored in a set of data of the same type with fixed length. an array is used to store data sets, but it is useful if you think of an array of variables with the same type.
  • Consolidating the ambition of self-driving cars, Intel plans to spend billions on acquiring Moovit trip planning applicationConsolidating the ambition of self-driving cars, Intel plans to spend billions on acquiring Moovit trip planning application
    with 800 million users worldwide, moovit's data and algorithms can be a powerful support to the self-driving car technology that intel is building.