检查数组排序日志(N) [英] Check if Array is sorted in Log(N)

查看:132
本文介绍了检查数组排序日志(N)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说,这可能与一些分而治之的算法来检查,如果一个数组排序的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.

这篇关于检查数组排序日志(N)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆