以下程序的时间复杂度为()。void fun(int n){int i=1;long sum=0do{sum+=t;i=i*3;} while(i<n);}
A.O(M)
B.O(nlog2n)
C.O(nlog2n)
D.O(log3n)
A.O(M)
B.O(nlog2n)
C.O(nlog2n)
D.O(log3n)
下面程序段的时间复杂度为 () s=0; for(i=1;i<n;i++) for(j=1;j<i;j++) s+=i*j;
A.O(1)
B.O(log2n)
C.O(n)
D.O(n3)
若有以下程序:
#include using namespace std ; class Point { int x, y; public :
Point () { x = 0; y = 0; } void SetPoint (int x1, int y1) { x = x1; y = y1; } void DisPoint () { cout << "x=" << x << "," << "y=" << y << endl ; } }; int main() { Point * p = new Point ; p-> SetPoint (5, 12); p-> DisPoint (); delete p; return 0; } 上面程序的输出结果为:
A.n
B.n^2
C.lg(n)
D.n^3
阅读下列程序,请写出程序的运行结果。
import java.applet.*;
import java.awt.*;
public class C extends Applet implements Runnable
{
Thread redBall,blueBall;
Graphics redPen,bluePen;
int blueSeta=0,redSeta=0;
public void init()
{
setSize(250,200);
redBall=new Thread(this);
blueBall=new Thread(this);
redPen=getGraphics();
bluePen=getGraphics();
redPen.setColor(Color.red);
bluePen.setColor(Color.blue);
setBackground(Color.gray);
}
public void start()
{
redBall.start();
blueBall.start();
}
public void run()
{
intx,y;
while(true)
{
if(Thread.currentThread()==redBall)
{//以下代码为顺时针画圆
x=(int)(80.0*Math.cos(3.1415926/180.0*redSeta));
y=(int)(80.0*Math.sin(3.1415926/180.0*redSeta));
redPen.setColor(Color.gray);
redPen.fillOval(100+x,100+y,10,10);
redSeta+=3;
if(redSeta>=360)redSeta=0;
x=(int)(80.0*Math.cos(3.1415926/180.0*redSeta));
y=(int)(80.0*Math.sin(3.1415926/180.0*redSeta));
redPen.setColor(Color.red);
redPen.fillOval(100+x,100+y,10,10);
try{redBall.sleep(20);}
catch(InterruptedException e){}
}
elseif(Thread.currentThread()==blueBall)
{//以下代码为顺时针画圆
x=(int)(80.0*Math.cos(3.1415926/180.0*blueSeta));
y=(int)(80.0*Math.sin(3.1415926/180.0*blueSeta));
bluePen.setColor(Color.gray);
bluePen.fillOval(150+x,100+y,10,10);
blueSeta-=3;
if(blueSeta<=-360)blueSeta=0;
x=(int)(80.0*Math.cos(3.1415926/180.0*blueSeta));
y=(int)(80.0*Math.sin(3.1415926/180.0*blueSeta));
bluePen.setColor(Color.blue);
bluePen.fillOval(150+x,100+y,10;10);
try{blueBall.sleepp(40);}
catch(InterruptedException e){}
}
}
}
}
A.55 66
B.66 55
C.66 48
D.55 48
A.整个构建堆的时间复杂度为O(n)
B.堆排序是一种不稳定的排序算法
C.堆排序的时间复杂度为O(nlogn)
D.堆排序的空间复杂度为O(1)
A.4
B.5
C.3
D.6
算法频度函数f(n)=100n3+n2+1000的时间复杂度为();算法频度函数g(n)=25n3+5000n2的时间复杂度为();算法频度函数h(n)=n15+5000nlog2n的时间复杂度为()。(填空时O(n3)写为O(n3)即可)
A.20 10
B. 10 10
C. 10 20
D. 20 20