how to calculate run time

╄→尐↘猪︶ㄣ 提交于 2019-12-13 22:09:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!