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