简体   繁体   English

如果输入是排序的数据库还是未排序的,输入大小对算法时间复杂度是否重要?

[英]Does the input size matter for algorithm time complexity if the input is a sorted database versus non-sorted?

I have a theoretical question (if these are not allowed please direct me to the right place.) about time complexity.我有一个关于时间复杂度的理论问题(如果不允许,请指导我到正确的地方。)。

Say I have a list sorted lexically, and one that isn't.假设我有一个按词汇排序的列表,而一个不是。 I know that the linear search and binary search algorithms have vast differences in run-time (binary search being logarithmic so the input is halved each time), but other than that, will there be any significance about the size of the input for the sorted list versus the non-sorted list?我知道线性搜索和二分搜索算法在运行时间上有很大差异(二分搜索是对数的,所以每次输入减半),但除此之外,排序的输入大小是否有任何意义列表与非排序列表? Is there any other reason why the sorted list would be better, if the input is very large?如果输入非常大,排序列表会更好,还有其他原因吗?

Really new at this stuff so any clarification would be much appreciated!这东西真的很新,所以任何澄清都将不胜感激!

I know that the linear search and binary search algorithms have vast differences in run-time (binary search being logarithmic so the input is halved each time)我知道线性搜索和二分搜索算法在运行时有很大差异(二分搜索是对数的,所以每次输入减半)

This, and other similar algorithms, is the main advantage这和其他类似的算法是主要优势

will there be any significance about the size of the input for the sorted list versus the non-sorted list排序列表与非排序列表的输入大小有什么关系吗

No, each element occupies the same amount of space in RAM regardless of order (for a standard list).不,每个元素在 RAM 中占用相同数量的空间,无论顺序如何(对于标准列表)。

Is there any other reason why the sorted list would be better, if the input is very large?如果输入非常大,排序列表会更好,还有其他原因吗?

Advantages:优点:

  • Some algorithms are faster on sorted input sets一些算法在排序的输入集上更快
  • Sorted output can be more pleasing for end users if you are displaying it.排序后的 output 如果您要显示它,可能更适合最终用户。
  • Sorted data is easier to compress, so for storage on disk or specialized RAM storage it could be smaller, but it would make no difference if you just put it in a standard array or list.排序后的数据更容易压缩,因此对于存储在磁盘或专门的 RAM 存储中,它可能会更小,但如果你只是将它放在标准数组或列表中并没有什么区别。

There are probably more, this is what I can come up with offhand.可能还有更多,这是我可以随手想出的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM