检查数组排序日志(N)数组、日志

2023-09-11 07:09:58 作者:遗失的美好

我听说,这可能与一些分而治之的算法来检查,如果一个数组排序的log(n)。最快的方法,我知道是O(N)(通过名单只是运行,并检查是否元素大于previous)。

I heard that it's possible with some divide and conquer algorithm to check if an array is sorted in Log(N). The fastest way I know is O(N) (just running through the list and checking if element is greater than previous).

我在网上看了,但没有找到任何东西,但我想在这里问,如果有人放弃之前就知道了。

I looked online and couldn't find anything, but I thought to ask here if anyone knew before giving up.

推荐答案

要检查是否数组排序没有previous知识,你需要看的所有元素至少一次,所以O(n)是最低限度。

To check if an array is sorted with no previous knowledge, you need to look at all elements at least once, so O(n) is the minimum.