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;

}

}

  1. O(1)

  2. O(log N)

  3. O(N)

  4. 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;

}

  1. O(N log N)

  2. O(N)

  3. O(1)

  4. O(N2)

QUESTION 3:

When assessing the worst-case complexity of an if/else if structure, you should...

  1. Calculate the complexity of each branch and then take the average of all of them.

  2. Calculate the complexity of each branch and use the best-case one.

  3. Add the complexities of each branch together.

  4. Calculate the complexity of each branch and use the worst-case one.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!