<> preface

Algorithm is a necessary knowledge for a programmer , from now on , Come and learn the algorithm with me !

<> one , What is recursion

Recursion is the realization of recursion in computer programming , In short, it is a programming skill of program calling itself .

A method in which a procedure or function calls itself directly or indirectly in its definition or description , It usually transforms a large and complex problem into a smaller one similar to the original one , Recursion strategy only needs a few programs to describe the repeated calculation needed in the process of solving problems , It greatly reduces the code of the program

<> two , Use cases

There is a pair of rabbits , From the second day after birth 3 A couple of rabbits are born every month since the first month , The rabbits grow to the third month, and then give birth to a pair of rabbits every month , If the rabbits don't die , What is the total number of rabbits per month ?

First of all, analyze the problem :

The number of rabbits in the last few months was :1,1,2,3,5,8,13,21,34,55,89,144, From the data, it can be found that from the third month , The number of rabbits in each month is the sum of the number of rabbits in the first two months

At this time, a recursive condition is satisfied , We can use recursion in the program to achieve such a calculation :
int GetNub(int n) { int nub; if(n==1||n==2) nub=2; else nub = GetNub(n-1)+
GetNub(n-2); // Invoking itself in programs to simplify problems return nub; }
<> three , How to cultivate recursion thought

Recursion is often accompanied by the development of the timeline , And often before and after a certain connection , If this happens , Consider listing the previous data , And some rules are summarized

Technology
©2019-2020 Toolsou All rights reserved,
Hikvision - Embedded software written test questions C Language application 0 The length of array in memory and structure is 0 In depth analysis data structure --- The preorder of binary tree , Middle order , Subsequent traversal How to do it ipad Transfer of medium and super large files to computer elementui Shuttle box el-transfer Display list content text too long 2019 The 10th Blue Bridge Cup C/C++ A Summary after the National Games ( Beijing Tourism summary )unity Shooting games , Implementation of first person camera python of numpy Module detailed explanation and application case Study notes 【STM32】 Digital steering gear Horizontal and vertical linkage pan tilt Vue Used in Element Open for the first time el-dialog Solution for not getting element