I am having a hard time getting the complexity of this for-loop
for (i = 4; i < n; i++)
{
for (j = i - 3, sum = a[i - 4]; j <= i; j++)
{
sum += a[j];
}
System.out.println("sum thru" + i + ": " + sum);
}
I was thinking that the complexity of this nested loop is n^2 since it's a nested loop but someone told me that this is incorrect and nested loops aren't always a quadratic complexity!
I don't really know how to get the complexity in a good way. I've seen lots of articles about Big-O and complexity but they weren't helpful because they were expecting me to know everything, and they examples weren't the same as any of the examples I have.
I am not asking for the answer, I'm asking for the method. Is there any formula or method that will work for everything in this topic? I want to know how to get the number of assignments but unfortunately I have no clue how to do this.
Can someone explain it to me step by step?
n) becausejalways goes fromi-3toi. That means the inner loop always only has four iterations, a number independent ofn.