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.

Results 1 to 6 of 6

Thread: I need help for this time complexity measurment?

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I need help for this time complexity measurment?

    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...  
    			  
       }
    		 
    }
    Is this O(n2) or O(n4) or what ?? Can any of you convince me about this.

    Hope you got what i want.


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: I need help for this time complexity measurment?

    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.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: I need help for this time complexity measurment?

    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:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: I need help for this time complexity measurment?

    Quote Originally Posted by Sean4u View Post
    I didn't know you could put comma-separated statements in the for-loop in Java. When did that creep in?
    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).

  5. The Following User Says Thank You to helloworld922 For This Useful Post:

    Sean4u (September 16th, 2011)

  6. #5
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: I need help for this time complexity measurment?

    been in there from day one
    I had never previously heard of a 'comma operator' - it's nasty! Thanks for that.

  7. #6
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: I need help for this time complexity measurment?

    Quote Originally Posted by Sean4u View Post
    I had never previously heard of a 'comma operator' - it's nasty! Thanks for that.
    Yeah, it should be avoided if possible

Similar Threads

  1. First Time
    By rayoung17 in forum Member Introductions
    Replies: 1
    Last Post: April 4th, 2011, 01:52 PM
  2. [SOLVED] Run time error
    By moodycrab3 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 7th, 2011, 11:05 AM
  3. First time in forum
    By prasanth1216 in forum Member Introductions
    Replies: 0
    Last Post: December 19th, 2010, 01:45 PM
  4. 1st time using methods
    By gonfreecks in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 1st, 2010, 02:37 PM
  5. Using time
    By ellias2007 in forum Java Theory & Questions
    Replies: 1
    Last Post: September 4th, 2010, 08:48 AM