问题
when calculate run time of any algorithm ,we always ignore the constant such 3n+2 =O(n) why and why we ignore the run time of simple statements. and what difference between run time and execution time?
回答1:
The Big O notation is an asymptotic notation which got the idea from mathematics describing the behaviour of function in "limits".
The simple way of looking at asymptotic notation is that it discards all the constant factors in a function. Basically, a n^2 will always be bigger that b n if n is sufficiently large (assuming everything is positive). Changing the constant factors a and b doesn't change that - it changes the specific value of n where a n^2 is bigger, but doesn't change that it happens. So we say that O(n^2) is bigger than O(n), and forget about those constants that we probably can't know anyway.
- Compile time = take source code, make an executable.
- Run time = executable takes in input (from keyboard, mouse, network, etc.) and generates output.
来源:https://stackoverflow.com/questions/38908579/how-to-calculate-run-time