Chapter 1 Algorithm Overview

Characteristics: input, output, determinism, finiteness, feasibility.

(1) Input: There are 0 or more externally provided quantities as the input of the algorithm.

(2) Output: The algorithm produces at least one quantity as output.

(3) Deterministic: Each instruction that makes up the algorithm is clear and unambiguous.

(4) Finiteness: The number of executions of the algorithm is limited, and the time to execute each instruction is also limited.

(5) Feasibility: All operations in the algorithm are basic, in principle, they can be carried out accurately, and can be completed by a finite number of times.

Algorithm Complexity Analysis

nAlgorithm complexity = computer resources required by the algorithm

1. The time complexity of the algorithm T(n);

Refers to the computational effort required to execute an algorithm

2. The space complexity of the algorithm is S(n).

Refers to the memory space required to execute the algorithm

n where n is the size of the problem (input size), and T(n) is the number of basic operations (assuming that the time required for basic operations is in unit time)

The time complexity of the algorithm

(1) Worst-case time complexity

Tmax(n) = max{ T(I) | size(I)=n }

(2) Time complexity in the best case

Tmin(n) = min{ T(I) | size(I)=n }

(3) Time complexity in the average case

Tavg (n) =image

where I is an instance of size n of the problem, and p(I) is the probability that instance I occurs.

The time required by an algorithm to process an input with a problem size of n is called the time complexity of the algorithm. Denoted as T(n)

When the scale of the problem increases, the limit of time complexity is called asymptotic time complexity.

In general, for sufficiently large n, the usual time complexity exists in the following order:

O(1)< O(logn)< O(n)< O(n*logn)<O(n2)<O(n3)…

<O(2n)<O(3n)<…<O(n!)

image

image

image

image

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325482421&siteId=291194637