使用unix时间实用程序找到快速排序的thetha等价类
我使用 time 实用程序来计算输入为 10000,20000, ...,60000 个单词的快速排序算法的用户时间,这是我得到的结果我
n( in thousands) T(n)
1 1.740
2 3.7
3 5.83
4 7.93
5 10.18
6 12.41
想找出的是 f(n) 使得 T(n )= theta(f(n)) 即,我需要猜测 f(n) 使得 T(n)/f(n) 接近非零常数。 我尝试了以下 f(n) 函数,但似乎没有生成常量
f(n) =n
f(n) = nlogn
f(n) = n+sqrt(n)
f(n) = n^2
f(n)=n + logn
f(n)=1/n
根据我的推断,T(n) 将 n 作为下界,将 n log n 作为上限。所以我需要一个介于这两个值之间的函数。请帮忙。
I used the time utility to calculate the user time for a quicksort algorithm with inputs of 10000,20000, ...,60000 words and here are the results I have
n( in thousands) T(n)
1 1.740
2 3.7
3 5.83
4 7.93
5 10.18
6 12.41
What I want to find out is f(n) such that T(n)= theta(f(n)) i.e., I need to guess f(n) such that T(n)/f(n) approaches a non-zero constant.
I tried the following f(n) functions but nothing seems to generate the constant
f(n) =n
f(n) = nlogn
f(n) = n+sqrt(n)
f(n) = n^2
f(n)=n + logn
f(n)=1/n
From what I inferred, T(n) has n as lower bound and n log n as upper bound. So I need a function between these two values. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你有很多可能的选择。我首先将您的数据拟合到六个方程中的每一个,然后看看拟合效果如何。例如,如果您尝试绘制结果,您会立即发现它们几乎是一条直线。使用任何绘图软件都可以帮助您看到这一点。在科学和数学中,这始终是一个好主意:绘制结果!
我很懒,所以我使用 Excel 将直线拟合到您的数据,然后我找到了方程:
带有 R2 0.9995。即使 Excel 也会为您提供这些 R2 值,以告诉您数据的拟合程度如何(您希望 R2 尽可能接近 1)。现在,这个结果非常好,你可以停在那里,但我想我会尝试将你的数据拟合到方程的其余部分,看看我得到了什么。我发现最适合您的六个函数的是:
R2 优于 0.999!现在这真是一个非常合适的选择。当然,如果您想要更高的准确性,您可能应该在 Igor(免费)而不是 Excel 中尝试此操作。尤其是已知 Excel 会给出负 R2 值。
我认为最重要的信息是,您应该始终尝试绘制结果。这些天太容易了。在那之后,我认为你太关心重新发明轮子并自己推导出这些适合的东西。有很多软件可以为您完成此操作。
You have a lot of possible options there. I would start by fitting your data to each of the six equations and seeing what how well the fits work. For instance, if you tried plotting your results you would immediately see that they are in a nearly straight line. Using any graphing software would help you see this. In science and mathematics, this is always a good idea: plot your results!
I was lazy, so I used Excel to fit a straight line to your data and I found the equation:
with an R2 of 0.9995. Even Excel will give you these R2 values, to tell you how good the fit is to the data (you want R2 as close to 1 as possible). Now, this result is quite good, and you could stop there, but I thought I would try to fit your data to the rest of the equations and see what I got. I found that the best fit to your six functions was:
with an R2 of better than 0.999! Now THAT is a really good fit. Of course, if you want more accuracy, you should probably try this in Igor (which is free) instead of Excel. Especially since Excel has been known to give negative R2 values.
The take home message, I think is that you should always try plotting your results. It's so easy these days. After that, I think you were too concerned about re-inventing the wheel and deriving these fits yourself. There is plenty of software to do this for you.