2.11. Discussion QuestionsΒΆ
Give the Big-O performance of the following code fragment:
int count = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
count = count +1;
}
}
Give the Big-O performance of the following code fragment:
int count = 0;
for (int i = 0; i < n; i++){
count = count + 1;
}
Give the Big-O performance of the following code fragment:
int i = n;
int count = 0;
while (i > 0){
count = count + 1;
i = i / 2; //Note: integer division
}
Give the Big-O performance of the following code fragment:
int count = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++){
for (int k = 0; k < n; k++){
count = count +1;
}
}
}
Give the Big-O performance of the following code fragment:
int count = 0;
for (int i = 0; i < n; i++){
count = count + 1;
}
for (int j = 0; j < n; j++){
count = count + 1;
}
for (int k = 0; k < n; k++){
count = count + 1;
}
You have attempted of activities on this page