Mathematical thinking and programming thinking

Source: Internet
Author: User

1. No mathematical basis for programming

2, but understand math does not mean to understand programming

To give an example:

Seek the 1+2+3+4+......+99+100 and.

The mathematical solution is usually:

1, (1+100) *100/2=5500

2, the pupil's solution: 1+2=3, 3+3=6 、...... So tired to go on.

What about the programming solution? The same as the mathematical solution 2, the code is as follows:

Static void Main (string[] args)        {            int0;              for (int1; + +i)            {                + = i;            }            Console.WriteLine (Theresult.tostring ());        }

So:

When programming solves a problem, you need to understand several logical reasons:

1, the computer operation speed is very fast

2, the computer will not be wrong, unless your code has a bug

So:

For example, 1 to 100 of sums, mathematics can use skills, program (computer) because he is fast and can not make mistakes, the most stupid way to calculate.

This is programming thinking and mathematical thinking.

The programming algorithms are:

1. Poor Lifting method

2. Greedy algorithm

3. Dynamic Programming method

Wait a minute

The example above is the poor lifting method in the programming algorithm.

Mathematical thinking and programming thinking

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.