2021-04-26

How should I express the complexity of two nested loops

I know the complexity of two for loops like that is x^2

for(i;i<x;i++){
   for(j;j<x;y++){
      //code
   }
}

but how about the complexity of two for loops while the nested one depends on the value of the first one, like that :

So I know that the time complexity of:

for(i; i<x; i++){
   for(y; y<i; y++){
      //code
   }
}

is the sum of integers of i as in the famous n(n+1)/2



from Recent Questions - Stack Overflow https://ift.tt/32Kh9ol
https://ift.tt/eA8V8J

No comments:

Post a Comment