Question: what is time complexity of the following code? void function ( ) { int sum = 0 ; for ( int i = 1 ;

what is time complexity of the following code?

void function()

{

int sum =0;

for (int i =1; i <=100; i++)

{

int x = i;

while (x !=0){

sum += x;

x /=2;

}

}

printf("%d", sum);

}





Step by Step Solution

3.34 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Lets analyze the time complexity of the given code 1 The outer loop runs from ... 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!