algorithm: An algorithm is a description of the solution steps for a particular problem, represented as a finite sequence of instructions in a computer, and each instruction represents one or more operations.
Why is the data structure and algorithm said together?
Think of Romeo and Juliet, Butterfly and Lovers, missing one you will always find it strange.
Five basic features of the algorithm:
- Input: There are 0 or more inputs;
- Output: 1 or more outputs;
- Have the poor sex: The step is limited, cannot infinite cycle goes down;
- Certainty: There is definite meaning, can not appear two semantics;
- Feasibility: Each step can be completed in a limited number of times.
Requirements for algorithmic design:
- Correctness: can correctly reflect the problem, get the correct answer to the problem;
- Readability: Easy to read, understand and communicate;
- Robustness: Even if the input is not legal, the algorithm can be processed, rather than the exception or abort;
- Time is efficient and storage is low: Like the people in life want to spend the least time, do the biggest thing.
The method of measuring the efficiency of the algorithm:
- Afterwards statistic method: Use the test good program and the data, use the computer to test the running time judgment algorithm's merits and demerits. This method has great shortcomings, must be designed in advance procedures, the risk of large, time is likely to rely on computer hardware configuration, algorithm testing data selection difficulties, such as the size of the data volume will affect the run time.
- Pre-analysis and estimation method: estimate before programming. Depends on the following factors: the algorithm adopted the strategy, the method (the root of the algorithm is good or bad), the Code quality (software) generated by the compilation, the input scale of the problem, the speed of machine instruction execution (hardware condition).
Algorithm time Complexity deduction method:
- Replaces all the addition constants in the run time with row number 1, for example, the time complexity of f (n) =1,f (n) =5 is O (1), also known as Constant street;
- In the modified run Count function, only the highest order items are retained;
- If the highest order exists and is not 1, the constant multiplied by the item is removed.
The result is the Big O-order.
Big liar data Structure--algorithm