# Time complexity - foor loop

• 02-28-2009, 04:51 PM
hawaiifiver
Time complexity - foor loop
Hello to all.

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

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!
• 02-28-2009, 05:00 PM
CJSLMAN
ah.... huh?
Sounds impressive, but I have no clue what you want.
Quote:

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
• 02-28-2009, 05:14 PM
hawaiifiver
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)
• 02-05-2011, 05:01 PM
ramya victor
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.
• 02-05-2011, 05:02 PM
ramya victor
can u tell wheteher i am correct? my sir has thought us like dat. plzzz tell me if am correct
• 02-05-2011, 05:06 PM
Fubarable