Question: Calculate the time complexity for the following function in terms of Big O notation. Explain your answer. [Note: Line numbers are only for reference purpose]

Calculate the time complexity for the following function in terms of Big O notation. Explain your answer.

[Note: Line numbers are only for reference purpose]

int fun(int n)

{

1 intcount = 0;

2 for (int i = n; i >= 0; i /= 2)

3 count += i;

4for (int j = 0; j < n; j++)

5count +=j;

6 return count;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To calculate the time complexity of the given function funint n lets analyze each part separately 1 ... View full answer

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 Programming Questions!