What is the complexity of the following C code segment Show

What is the complexity of the following C++ code segment? (Show your work.) void UnsortedType:Deteteltem(int a, float b) {a = a/3: b = a. for (int i = 0; i

Solution

1. for(int i =0; i<n; i++) {

for(j=1; j<n; j++) {

a=a*2;

}

}

Here for each value of i, j is iterated from 1 to n i.e. n-1 times. We can say in other way that for one value of i inner loop would be executed n-1 times.

And outer loop would be executed n times. So total n*(n-1) would be the complexity.

 What is the complexity of the following C++ code segment? (Show your work.) void UnsortedType:Deteteltem(int a, float b) {a = a/3: b = a. for (int i = 0; i Sol

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site