Results 1 to 6 of 6
Thread: Time complexity - foor loop
- 02-28-2009, 03:51 PM #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.
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?Java Code:for (int i = 1; i < n; i +=10) { for (int j = n; j > 0; j --) { product *= (i*j); } }
Thanks again!
- 02-28-2009, 04:00 PM #2
ah.... huh?
Sounds impressive, but I have no clue what you want.
The above is a correct statement.The inner loop executes n times for each run of the outer loop.
- 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,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 02-28-2009, 04:14 PM #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)
- 02-05-2011, 04:01 PM #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.
- 02-05-2011, 04:02 PM #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
-
Please don't hijack another's thread. If you have a question, please ask it in its own thread. Locking.
Similar Threads
-
Please tell me I am not crazy... Time Complexity (Big-O) Question
By Jordan in forum New To JavaReplies: 2Last Post: 11-04-2008, 02:48 AM -
Time
By Fireking in forum New To JavaReplies: 3Last Post: 09-07-2008, 01:30 AM -
i click on it,then first time error page comes,second time click then product page co
By 82rathi.angara in forum New To JavaReplies: 21Last Post: 08-01-2008, 11:13 AM -
Singleton considered stupid, Java and complexity
By fishtoprecords in forum Forum LobbyReplies: 11Last Post: 07-06-2008, 03:38 AM -
Hello, first time here.
By ludragon in forum IntroductionsReplies: 2Last Post: 01-03-2008, 05:03 AM


LinkBack URL
About LinkBacks

Bookmarks