Question: I WOULD LIKE FOR SOMEONE TO HELP ME ANSWER THESE THREE QUESTIONS BASED OF COMPUTER SCIENCE. JUST COMMENT THE ANSWER (IF POSSIBLE) GIVE AN EXPLENATION.
I WOULD LIKE FOR SOMEONE TO HELP ME ANSWER THESE THREE QUESTIONS BASED OF COMPUTER SCIENCE. JUST COMMENT THE ANSWER (IF POSSIBLE) GIVE AN EXPLENATION. THANKS :)
QUESTION 1: What is the worst-case complexity of the following code fragment:
for(i = 0; i < N; i++)
{
for(j = N; j > 1; j--)
{
cout << i * j << endl;
}
}
-
O(1)
-
O(log N)
-
O(N)
-
O(N2)
QUESTION 2:
What is the worst-case complexity of the following code fragment:
int* vals = new int[N];
for(i = 0; i < N; i++)
{
vals[i] = i * i;
}
for(j = 0; j < N; j++)
{
cout << vals[j] << endl;
}
-
O(N log N)
-
O(N)
-
O(1)
-
O(N2)
QUESTION 3:
When assessing the worst-case complexity of an if/else if structure, you should...
-
Calculate the complexity of each branch and then take the average of all of them.
-
Calculate the complexity of each branch and use the best-case one.
-
Add the complexities of each branch together.
-
Calculate the complexity of each branch and use the worst-case one.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
