Data Structure Learning notes (I) Basic concepts and analysis algorithms and basic concepts of Algorithms
The efficiency of the solution is related:
Data Organization (bookshelves)
Space Utilization (recursion and non-recursion)
Algorithm used to solve the problem
What is an algorithm: a data object must be associated with a series of operations added to it, and the method used to complete these operations is an algorithm.
Algorithm features:
A finite Instruction Set (poor)
Sometimes some input may not exist (input)
Generate output)
Stop after certain steps (poor)
The following conditions must be met for each instruction:
There are well-defined goals that cannot be ambiguous. (Deterministic)
Within the scope that the computer can process.
The description does not depend on any computer language and is specific to the implementation means.
Algorithm evaluation:
Space complexity S (n): The program written according to the algorithm occupies the length of the storage unit during execution (too large, program interrupted)
Time Complexity T (n): the length of the execution time of a program written according to the algorithm. (The result is not returned. Calculate the number of multiplication and division, or select an original operation that is a basic operation for the study. addition and subtraction are not counted)
Why are all n functions: because both evaluations are related to the scale of the problem.
Tworst (n) Worst time complexity> = average Tavg (n) Complexity generally uses average complexity, because the worst time complexity is easier to calculate
A large O indicates that f (n) is the upper bound of T (n). A large Ω indicates that f (n) is the lower bound of T (n ).
Tips for complex analysis:
If the complexity of the two algorithms is T1 (n) = O (f1 (n) and T2 (n) = O (f2 (n ),
T1 (n) + T2 (n) = max (O (f1 (n), O (f2 (n )));
T1 (n) * T2 (n) = O (f1 (n) * O (f2 (n ));
If T (n) is a k-order polynomial of n, T (n) = O (k power of n) (max)
The time complexity of the for Loop = the number of cycles multiplied by the complexity of the Code
If-else time complexity = max (if condition complexity, complexity of two branches)