gpt4 book ai didi

c++ - 时间复杂度

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:55:39 25 4
gpt4 key购买 nike

<分区>

这道题是为了复习过去的试卷我只想知道我是否在正确的轨道上

1. int i=1;
2. while (i <= n) {
3. for (int j=1; j<10; j++)
4. sum++;
5. i++;
6. }
7. for( int j = 1; j <= n; j++ )
8. for( int k = 1; k <= n; k=k*2 )
9. sum++;

1.) How many times is statement 4 executed?
A. O(n)
B. O(n^2)
C. O(log n)
D. O(n log n)
E. none of the above

这里我选择了A

2.) How many times is statement 9 executed?
A. O(n)
B. O(n^2)
C. O(log n)
D. O(n log n)
E. none of the above

因为第8行(k=k*2)我选了C

3.) What is the running time of the entire code fragment?
A. O(n)
B. O(n^2)
C. O(log n)
D. O(n log n)

因为O(n)+O(logn)=O(n)所以我选择了A

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com