Outline
1. Relationship between n and n + 1
The conclusion must be determined by an integer n.
The conclusion must be clearly defined so that we can test whether the conclusion can be established when the transition from item n to item n is n + 1.
We expect this result:
As long as this conclusion is true for n, n + 1 is also true. So we have two things to do. One is to confirm that the conclusion is correct when taking a value, and the other is to confirm that the next value is correct.
If we take a value, what should we take for it? Obviously, we all want to start from the simplest situation, so taking 1 is our choice, that is, n = 1.
Therefore, n = 1 is true, so n + = 1, that is, n = 2 is also true. Similarly, n = 3 is also true. From any integer to the next one, we generally prove this conclusion. The general proof shows that we have traversed all the situations. Similar to traversing a set, we only need to get the first node (n = 1), then it is next, and then next ...... You can traverse the entire set.
We often use this method to prove something, so it is better to give it a name. What is it? A straight view is simply called "proof from n to n + 1" and "proof that the next integer is correct. Unfortunately, the name of a major is "mathematical induction".
The name is random, but it doesn't matter. What we need to understand is the process behind it.
2. Fibonacci Series
Use an array to explicitly represent the relationship between the front and back positions
Long Fib (int n) {var list = new List <int> (); list [0] = 0; list [1] = 1; for (var I = 2; I <n; I ++) {list [I] = list [I-1] + list [I-2];} return list [n-1];}
Recursion uses the call stack to implicitly represent the relationship between positions.
3. tail recursion