0:00

Which best characterizes the running time of the following code segment?

for (int j = 1; j <= n; j++) {
   for (int k = 1; k <= n; k = k * 2)
      System.out.println(j + " " + k);
}
因在内层循环中k呈指数增长,故其运行时间为n的对数。总的运行时间是内外的乘积。
2


陈 欣

AADPS创始人

发表评论