The first phase algorithm to explain: On time complexity

I. Definition and importance of time complexity

Kai-fu Lee in "the power of the algorithm," one paper wrote:

\ (1988 \) years, vice president of Bell Labs in person to visit my school, the purpose is to find out why they are several times slower speech recognition system than my development, but also in the expansion of the speed difference to large vocabulary system after more hundreds of times as much ...... discussing with them the course, I was surprised to find that a \ (O (nm) \) of dynamic programming is that they actually made a \ (O ({n} ^ { } m 2) \) ......

The above-mentioned \ (O (nm) \) and \ (O ({n} ^ {2} m) \) is the time complexity. Symbol \ (O \) represents the complexity inside \ (Mn \) can be considered the number of runs is \ (n-m * \) .
Time complexity significance lies in energy efficiency have a reasonable amount of time .
In the previous example, if the system is running Kai-fu Lee's time \ (10 \) seconds, n-= \ (1000 \) , then the program needs to Bell \ (10000 \) seconds. This is a staggering figure.

Someone asked me: it was not there Supercomputer (supercomputers) it, people divinity Taihu light can run per second \ (^ {10} {17} \) times too!
I replied: another powerful supercomputer could not carry large data ah!

Probably second common computer \ (^ {10} {7} \) times, the former is the \ (^ {10} {10} \) times.
However, such a search, the time complexity of the segment tree is \ (O (\ log n-{}) \) , a sequential search is \ (O (n-) \) .
Set \ (n-\) is the size of data;
for school census, \ (n-3000 = \) , the former \ (4 \) times, the latter \ (3000 \) views;
the city census, \ (n-2 = * {10} {7} ^ \) , the former \ (8 \) times, the latter \ (* 2 ^ {10} {7} \) times;
nationwide census, \ (n-10} = {1.3 * 9 ^ {} \) , the former \ (10 \) times, the latter \ (1.3 * 10 {9} ^ {} \) times.

To world-class, if not pay attention to algorithm, supercomputing time may also run slower than normal computer ......

Visible algorithm selection is important !

II. Experience the time complexity

You can take a look by writing code.

As input and output arrays, time complexity is \ (O (2n) \)

#include<bits/stdc++.h>
using namespace std;
int main()
{
    return 0;
}
{
    
}

Guess you like

Origin www.cnblogs.com/SuperTer/p/algorithm-1.html