0
Find how many times the this code will run in terms of n
for (i = 1; i < n; i ++) for(j = n; j > i; j --) I am supposed to calculate the number of times it will run in terms of n. And find the upper bound. I know the outer for loop runs n - 1 times, but am confused how to find the amount of times the inner loop runs
2 Answers
+ 2
Why don't you just run it like this?
int i,j,n=6;
for (i = 1; i < n; i ++)
{
for(j = n; j > i; j --)
{
System.out.println("hi");
}
System.out.println();
}
It will also run n-1 times.
0
It is something like this i*(n-i) ,1*(5-1),then 2*(5-2) and so on maybe 10 times