2.10. Discussion QuestionsΒΆ

  1. Give the Big-O performance of the following code fragment:
for (int i = 0; i < n; i++){
   for (int j = 0; j < n; j++){
       k = 2 + 2;
   }
}
  1. Give the Big-O performance of the following code fragment:
for (int i = 0; i < n; i++){
   k = 2 + 2;
}
  1. Give the Big-O performance of the following code fragment:
int i = n;
while (i > 0){
   k = 2 + 2
   i = i // 2
}
  1. Give the Big-O performance of the following code fragment:
for (int i = 0; i < n; i++){
    for (int j = 0; j < n; j++){
        for (int k = 0; k < n; k++){
            k = 2 + 2;
        }
    }
}
  1. Give the Big-O performance of the following code fragment:
for (int i = 0; i < n; i++){
    k = 2 + 2;
}
for (int j = 0; j < n; j++){
    k = 2 + 2;
}
for (int k = 0; k < n; k++){
    k = 2 + 2;
}
Next Section - 2.11. Programming Exercises