// For the below algorithm, calculate the exact number of times
// System.out.println statement is executed as a function of n. Assume n≥1
for (int i=0; i<=n; i++) {
for (int j = i; j < 2*n; j++) {
System.out. println(”1 iteration executed!”);
}
}
这是解决方案,但我很难理解数学。
Overall RT = 2n + (2n-1) + (2n-2) + … + n =
= (n+1)*n + (n+(n-1)+(n-2)+…+1+0) =
= n2 + n + n*(n+1)/2 =
= 1.5*n2 + 1.5n
蝴蝶不菲
哈士奇WWW
相关分类