Following the algorithm of the Small turtle Learning Algorithm first experience (1)

Source: Internet
Author: User

Download the small turtle's algorithm and data structure video from the Internet, and intend to finish the series with the video. To achieve a preliminary understanding of the algorithm

    • What is an algorithm?

An algorithm is a description of the solution steps for a particular problem, represented as a finite sequence of instructions in the computer, and each of the bars represents one or more operations. (In short, the algorithm is the skill and the way to do all kinds of things)

Remember the primary school, the teacher for everyone told the German big data of Gauss's story, content is Gauss's teacher asked the class from 1 to 100 to find out and. When everyone is immersed in the bitter calculation, Gauss takes a short time to get the result. Gauss uses the method is 1+100,2+99,3+98 ... all get 101, then from 1 to 100 and 50 to 101. 50x101=5050 This is far more than from 1 to 100 faster, this is the efficiency of the algorithm. The following program demonstrates:

1  Private Static intSUANFA1 (intN) {2         intSum=0;3          for(inti = 1; I <=n; i++) {4sum+=i;5         }6         returnsum;7     }8 9     Private Static intSUANFA2 (intN) {Ten         intSum=0; Onesum= (1+n) * (N/2); A         returnsum; -}
View Code

The algorithm of the Small turtle Learning Algorithm first experience (1)

Related Article

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.