# Thread: Time complexity - foor loop

1. Member Join Date
Jan 2009
Posts
21
Rep Power
0

## Time complexity - foor loop

Hello to all.

I am trying to figure out the time complexity for the following piece of code.

Java Code:
```for (int i = 1; i < n; i +=10)
{

for (int j = n; j > 0; j --)
{

product *= (i*j);
}

}```
Should I be thinking here about the fact that there are two foor loops? The inner loop executes n times for each run of the outer loop. I think this might have something to do with quadratic time. Or should i be looking at statements like product *= (i*j); Any tips?

Thanks again! 2. ## ah.... huh?

Sounds impressive, but I have no clue what you want.
The inner loop executes n times for each run of the outer loop.
The above is a correct statement.

• Are you looking for the mathamatical interpretation for the above?
• Do you want to know which is more efficient: the above or product *= (i*j)?
• Do you want to use these in a program or are asking for some other reason?

Luck,
CJSL 3. Member Join Date
Jan 2009
Posts
21
Rep Power
0

## Hi CJSL,

Yes I am trying to figure out the time complexity of the code.
I'm not using it in a program or looking for a mathematical interpretation.

I am trying to write the time complexity in big Oh notation.

If n = 50. Then the number of multiplications in the inner loop will be 50. In my notes it says the time taken to complete what the code is doing is approximately proportional to n.

Would it be reasonable to assume that the time complexity is of order n, i.e O(n) 4. Member Join Date
Feb 2011
Posts
2
Rep Power
0

## time complexity

is the time complexity of this code is 0(n2). the outer for loop is executed n times and inner for loop is executed and hence the inner code is executed n*n= n2 times. 5. Member Join Date
Feb 2011
Posts
2
Rep Power
0

## can u tell wheteher i am correct? my sir has thought us like dat. plzzz tell me if am correct 6. ##  