Big Talk Data Structure-C (2)

Two: algorithm

        A description of the steps to solve a particular problem, represented in a computer as a finite sequence of instructions, with each instruction representing one or more operations.

2.1 Characteristics of the algorithm

        Algorithms have five basic properties: input, output, finiteness, certainty, and feasibility.

1) Input and output:

        An algorithm has zero or more inputs and at least one or more outputs. There is no point in using this algorithm without output.

2) Finiteness:

        After the algorithm executes a finite number of steps, it automatically ends without an infinite loop, and each step is completed within an acceptable time.

3) Certainty:

        Each step of the algorithm has a definite meaning without ambiguity.

4) Feasibility:

        Each step of the algorithm must be feasible, that is, each step can be executed a finite number of times.

        When judging the efficiency of an algorithm, the constants and other secondary terms in the function can often be ignored, and more attention should be paid to the order of the main term (the highest order term).

2.2 Time complexity of the algorithm

       When analyzing the algorithm, the total execution times T(n) of the statement is a function of the problem size n, and then analyze the variation of T(n) with n and determine the magnitude of T(n). The time complexity of the algorithm, that is, the time measure of the algorithm, is denoted as T(n)=O(f(n)). It means that with the increase of the problem size n, the growth rate of the algorithm execution is the same as the growth rate of f(n), which is called the asymptotic time complexity of the algorithm, or time complexity for short. where f(n) is some function of the problem size n.

 

2.2.1 Common time complexity

 2.3 Space complexity of the algorithm

        The space complexity of the algorithm is realized by calculating the storage space required by the algorithm. The calculation formula of the space complexity of the algorithm is recorded as: S(n)=O(f(n)), where n is the scale of the problem, f(n) is a function of the statement about the storage space occupied by n.

Guess you like

Origin blog.csdn.net/weixin_44285713/article/details/130081286