详细的大哦问题
所以,我对作业中的这个问题有点困惑。
for ( int j = 0; j < 2*n; j++){
for ( int k = 0; k < n * n * n; k += 3)
sum++;
}
有点困惑之后得出了这个结论
所以我在对( 1, 2n, n)
对于( 1/3( 1, 3n, 1)
我把它设置为 1/3,因为它增加了 3。我只是不确定我是否正确,我们刚刚被介绍到这个,所以我有点迷失了。
So, I'm slightly confused by this question on my homework.
for ( int j = 0; j < 2*n; j++){
for ( int k = 0; k < n * n * n; k += 3)
sum++;
}
So I am at this conclusion after a bit of confusion
for( 1, 2n, n)
for( 1/3( 1, 3n, 1)
I have it as 1/3 because it's going up by 3. I'm just not sure if I'm right, we were just introduced to this so I'm sorta lost.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不完全确定我明白你在问什么...假设问题是这个嵌套循环的 Big-O 表示法是什么(并假设加法操作是基本操作)
2n
次n^3/3
次这意味着内层语句被执行
2n
*n^3/3
=(2/3)*n^4
。对于 Big O 表示法,我们忽略常量,因此这个嵌套循环的复杂度为 O(n^4)。I'm not completely sure that I understand what you are asking... Assuming that the question is what the Big-O notation for this nested loop would be (and assuming that the addition operation is the base operation)
2n
timesn^3/3
times for each iteration of the outer loopThat means that the inner statement is executed
2n
*n^3/3
=(2/3)*n^4
. For Big O notation, we ignore the constants, so this nested loop is O(n^4).