Results 1 to 6 of 6
Thread: Time complexity  foor loop
 02282009, 03:51 PM #1Member
 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); } }
Thanks again!
 02282009, 04:00 PM #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.
 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.
 02282009, 04:14 PM #3Member
 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)
 02052011, 04:01 PM #4Member
 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.
 02052011, 04:02 PM #5Member
 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 (BigO) Question
By Jordan in forum New To JavaReplies: 2Last Post: 11042008, 02:48 AM 
Time
By Fireking in forum New To JavaReplies: 3Last Post: 09072008, 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: 08012008, 11:13 AM 
Singleton considered stupid, Java and complexity
By fishtoprecords in forum Forum LobbyReplies: 11Last Post: 07062008, 03:38 AM 
Hello, first time here.
By ludragon in forum IntroductionsReplies: 2Last Post: 01032008, 05:03 AM
Bookmarks