Method 1: Compare every two in order and choose the larger one.
If (a & gtb) {
max = a;
} Otherwise {
max = b;
}
if(max & lt; c) {
max = c;
}
Method 2: Assuming that the first number is the largest, compare it with the last two numbers and assign a larger value to max.
int max = a;
If (b> max) {
max = b;
}
if(c & gt; Max) {
max = c;
}
1, what is an algorithm?
Algorithm: It is a defined calculation process. It accepts one or a set of values as input and produces one or a set of values as output. Simply put, an algorithm is a series of calculation steps that transform input data into output results.
Mark: We can think of all the algorithms as a "cookbook". For a specific algorithm, such as the making process of an "old vinegar peanut" on the menu, anyone can make delicious old vinegar peanuts as long as they are made according to the requirements of the menu. Therefore, this cooking step can be understood as a "problem-solving step"
2. The significance of the algorithm
Assuming that the computer is infinitely fast and the computer storage container is free, do we still need all kinds of messy algorithms? If the computer is infinitely fast, then any correct method can solve a problem!
Of course, computers can be fast, but not infinitely fast, and storage can be cheap but not free.
Then the problem comes to efficiency: the efficiency of different algorithms to solve the same problem is often very different, and the impact of this efficiency gap is often greater than that of hardware and software.
3. How to choose an algorithm
First of all, we must ensure the correctness of the algorithm.
An algorithm is correct if it can output the correct result for each input instance and stop. We say that a correct algorithm solves the given calculation problem. For some inputs, incorrect algorithms may not stop at all, or give unexpected results when they stop. However, contrary to people's views on incorrect algorithms, these algorithms are sometimes useful if the error rate can be controlled. But in general, we still only focus on the correct algorithm!
Time complexity of the second analysis algorithm
The time complexity of the algorithm reflects the order of magnitude that the program execution time increases with the increase of input scale, which can reflect the quality of the algorithm to a great extent.