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.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to find the time complexities

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Thanked 0 Times in 0 Posts

    Post How to find the time complexities

    This is a simple code I made. Can somebody tell me how to find the time complexity of this code?
    Here is the code:

    for(i = 0;  i<  n; i++)
    	for(j =1; sum = a[0]; j <= i; j++)
    	sum += a[j];
    	system.out.println (“sum of the array is” + sum);

    Thank you....

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Washington, DC
    My Mood
    Thanked 636 Times in 540 Posts

    Default Re: How to find the time complexities

    What do you think the answer is? What happened when you wrote a few test programs to try it out yourself?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Thanked 0 Times in 0 Posts

    Default Re: How to find the time complexities

    When looking at the complexity of code, you have to think, for a set of n elements, how long does this take to execute. Hint: the answer is not a fixed number. Hint#2: the number of lines in a loop doesn't change the complexity of the code necessarily, but the number of times you need to look through a set of n numbers can.

Similar Threads

  1. Problem in getting time of different time zone
    By anks.coder in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 13th, 2013, 05:44 PM
  2. Find maximum working time [Urgent]
    By loong424 in forum Algorithms & Recursion
    Replies: 4
    Last Post: August 22nd, 2013, 03:18 AM
  3. Using Date() to get Start Time and Finish Time of a copyFiles method
    By dalythe in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 17th, 2013, 09:50 PM
  4. Hello, first time caller long time programmer....
    By P2C2N in forum Member Introductions
    Replies: 3
    Last Post: December 10th, 2012, 11:53 AM
  5. Replies: 2
    Last Post: October 19th, 2012, 03:32 AM

Tags for this Thread