2nd Chapter Algorithm

Source: Internet
Author: User

algorithm definition: an algorithm is a description of the solution steps for a particular problem, a finite sequence of instructions in the computer, and each instruction represents one or more operations.
features of the algorithm:
1.0 or more inputs, at least one or more outputs
2. Have poor sex
3. Certainty: Each step has a definite meaning, no ambiguity, that is, the same input can only have a unique output
4. Feasibility: Each step can be achieved through the implementation of a limited number of times
Requirements for algorithmic design:
1. Correctness
2. Readability (easy to read, understand and communicate)
3. Robustness (when the input data is not legal, ...) )
4. High time efficiency and low storage rate
The time complexity of an algorithm can be analyzed based on the asymptotic growth of the key execution times function of the algorithm.
Algorithm time complexity to tear down the steps of the large o -step:
1. Replace all the addition constants in the run time with constant 1.
2. In the modified run Count function, only the highest order is preserved.
3. If the highest order exists and is not 1, the constant multiplied by the item is removed.
Example 1:

intcount1;while(count < n){    countcount2;}

x = log2n is obtained from 2x = n, so its time complexity is O (log n).
Example 2:

i,j;for(i=0ii++){    print("%d", i);}for(i=0ii++){    for(j=i; j<n; j++)        print("%d", j);}

The number of executions is n+[n (n+1)]/2, according to the method of demolishing Big O, the time complexity of this code is O (square of N).
O (1) < O (log n) < O (n) < O (n*log N) < O (square of N) < O (cubic of N) < O (2 N-squared) < O (n!) < O (n-th-square)
Unless specifically specified, the runtime we mentioned is the worst-case run time.
The algorithm has the complexity of time and space .

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

2nd Chapter Algorithm

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.