Mathematical induction and Recursion also include the Fibonacci series (unfinished)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.