Question: Calculate the time complexity of each algorithm listed below: algorithm - 1 int sum() { sum=0; for(int i=0; i <10; i++) { sum = sum+1;

Calculate the time complexity of each algorithm listed below:

algorithm - 1

int sum()

{

sum=0;

for(int i=0; i<10; i++)

{

sum = sum+1;

}

return sum;

}

algorithm - 2

int sum(int m)

{

sum=0;

for(int i=0; i

{

sum = sum+1;

}

return sum;

}

algorithm - 3

int sum(int m)

{

sum=0;

for(int i=0; i

{

for(int j=0; j<10; j++)

sum = sum+1;

}

return sum;

}

algorithm - 4

int sum(int m)

{

sum=0;

for(int i=0; i

{

for(int j=0; j

sum = sum+1;

}

return sum;

}

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!