Is this O(n2) or O(n4) or what ?? Can any of you convince me about this.HTML Code:for(int i= 0,j= 0; i< n; i++,j++ ) { for(int a= 0,b= 0; a< n; a++,b++ ) { 1 statement goes here... } }
Hope you got what i want.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Is this O(n2) or O(n4) or what ?? Can any of you convince me about this.HTML Code:for(int i= 0,j= 0; i< n; i++,j++ ) { for(int a= 0,b= 0; a< n; a++,b++ ) { 1 statement goes here... } }
Hope you got what i want.
I didn't know you could put comma-separated statements in the for-loop in Java. When did that creep in?
i and a control the loops, j and b are dependent on them. A nest of two loops is [insert answer here]. Note that using this rule of thumb on loops is only valid - or at best only gives you a lower bound to your time complexity - if the "1 statement goes here" is an O(1) statement.
This thread has been cross posted here:http://www.java-forums.org/advanced-java/48592-i-need-help-time-complexity.html
Although cross posting is allowed, for everyone's benefit, please read:
Comma Operator
As far as I know, it's probably been in there from day one (I know it's present in the C/C++ language).
Sean4u (September 16th, 2011)
I had never previously heard of a 'comma operator' - it's nasty! Thanks for that.been in there from day one