我需要帮助理解/做大O符号.我理解它的目的,我只是不知道如何"确定给定一段代码的复杂性".
确定以下各项的Big O表示法
一个.
n=6;
cout<<n<<endl;
Run Code Online (Sandbox Code Playgroud)
湾
n=16;
for (i=0; i<n; i++)
cout<<i<<endl;
Run Code Online (Sandbox Code Playgroud)
C.
i=6;
n=23;
while (i<n) {
cout<<i-6<<endl;
i++;
}
Run Code Online (Sandbox Code Playgroud)
d.
int a[ ] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19};
n=10;
for (i=0; i<n; i++)
a[i]=a[i]*2;
for (i=9; i>=0; i--)
cout<<a[i]<<endl;
Run Code Online (Sandbox Code Playgroud)
即
sum=0;
n=6;
k=pow(2,n);
for (i=0;i<k;i++)
sum=sum+k;
Run Code Online (Sandbox Code Playgroud)