的code的复杂性 [英] complexity of code

查看:136
本文介绍了的code的复杂性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是只有一个循环程序的复杂性,这是日志N? 有人可以给我一些想法估计$复杂C $ CS?

what is the complexity of a program having only one loop, is it log n? can someone give me some ideas about estimating complexity of codes?

推荐答案

嗯,这实际上取决于在该循环回事。

Well, that really depends on what is going on in that loop.

这个循环是线性的时间,即O(N):

This loop is linear time, i.e., O(n):

int sum = 0;
foreach( int i in SomeCollection )
{
    sum += i;
}

不过,考虑环路执行每次迭代过程中一个字符串搜索。现在,你必须要考虑的字符串搜索算法的复杂度。因为它代表你的问题不能回答。你需要,如果你想有一个有意义的答案提供了code样本。

However, consider a loop which performs a substring search during each iteration. Now you have to consider the complexity of the string searching algorithm. Your question can't be answered as it stands. You will need to provide a code sample if you want a meaningful answer.

这篇关于的code的复杂性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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