这是什么意思:“检测到的时间复杂度:O((N+M)*K)”?

发布于 2024-11-05 08:00:51 字数 228 浏览 1 评论 0原文

我正在尝试在线开发人员认证网站的演示测试之一。我已经使用许多接口、事件等用 C# 编写了它。

我的代码通过了,但它抱怨:

检测到的时间复杂度:O((N+M)*K)

基本上 O((N+M)*K) 是什么意思?

如果我想修复这种复杂性(这是适用于数组的代码)通常最好从哪里开始检查?

更新:该代码适用于多维数组,并且它有一个循环内的循环(在某个点遍历行,然后遍历列)

I was trying one of the online developer certificating website's demo test. I have written it in C# using many interfaces, events etc.

My code passed but it complained that:

Detected time complexity: O((N+M)*K)

What does basically O((N+M)*K) mean?

And if I want to repair this complexity, (it is a code works on arrays) usually where is best to start checking?

Updates: The code works on multi-dimensional array and it has a loop within a loop (walks through rows and then columns at some point)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城仅有旧梦在 2024-11-12 08:00:51

这完全取决于您的代码应该做什么。

Big-Oh 告诉您决定算法需要多长时间的主要因素是什么。

It would completely depend on what your code is supposed to do.

Big-Oh tells you what the main factors are that determine how long your algorithm will take.

墨落成白 2024-11-12 08:00:51

这是 Big-O 表示法的示例:

http://en.wikipedia.org/wiki/Big_O_notation

我不知道您所拥有的类型的具体情况,但它告诉您的是有问题的方法,但它告诉您的是该方法的界限是它将运行多次(n +m)*k。

得出这个结论的方法是检查方法的内部循环与其在外部循环中运行的次数之间的关系。

事实上,它认为 '* k' 是一个因素,这意味着它警告您对于大型数组可能需要很长时间。

您可以发布方法本身吗?

This is an example of Big-O notation:

http://en.wikipedia.org/wiki/Big_O_notation

I don't know the specifics of the type that you've got, but what it's telling you is that the method in question but what it's telling you is that the bounds of the method are that it will run many times (n+m)*k.

How it's come to this conclusion is by examining the relationship of the internal loop of your method, to how many times its run in an outer loop.

the fact that it thinks '* k' is a factor means it's warning you that it could take a long time for large arrays.

Can you post the Method itself ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文