Log-log plot/graph of algorithm time complexity [closed]

我的未来我决定 提交于 2019-12-12 01:14:13

问题


I just wrote the quick and merge sort algorithms and I want to make a log-log plot of their run time vs size of array to sort.

As I have never done this my question is does it matter if I choose arbitrary numbers for the array length (size of input) or should I follow a pattern (something like 10^3, 10^4, 10^5, etc)?


回答1:


In general, you need to choose array lengths, for each method, that are large enough to display the expected o(n log n) or O(n^2) type behavior.

If your n is too small the run time may be dominated by other growth rates, for example an algorithm with run time = 1000000*n + n^2 will look to be ~O(n) for n < 1000. For most algorithms the small n behavior means that your log-log plot will initially be curved.

On the other hand, if your n is too large your algorithm may take too long to complete.

The best compromise may be to start with small n, and time for n, 2n, 4n,..., or n, 3n, 9n,... and keep increasing until you can clearly see the log log plots asymptoting to a straight lines.



来源:https://stackoverflow.com/questions/21535586/log-log-plot-graph-of-algorithm-time-complexity

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