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 7 of 7

Thread: Big O

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Big O

    I got this question , it is a theory question on Big 0
    1-if n is 2 what is the final value for counter
    2-if n is 5 what is the final value for counter
    3-in light of this derive a expression for the number of times the inner loop will run in terms of n
    4- state the Big O complexity

    int counter =0
    for (int i = n; i <=3*n; i ++){
    while(i >+n){
    i --:
    counter ++
    }
    }

    can anyone tell me how to get the values for counter


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,074
    Thanks
    47
    Thanked 2,147 Times in 2,120 Posts

    Default Re: Big O

    What happens when you compile and execute the code and print out the results?

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Big O

    it is not a question about the code, it is a theory question on Big O complexity. It asks to figure out what the value for counter is when the values are put in for n.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,074
    Thanks
    47
    Thanked 2,147 Times in 2,120 Posts

    Default Re: Big O

    Have you tried executing the code? what does it do?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Oct 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Big O

    program keeps running

  6. #6
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    939
    Thanks
    6
    Thanked 202 Times in 178 Posts

    Default Re: Big O

    Quote Originally Posted by shanem View Post
    program keeps running
    Then it has infinite complexity.

    If you suspect that it is intended to finish eventually then post the code you are using. And describe the program's behaviour: especially the output suggested by Norm in #2.

    [Edit] I think a couple of values for n as suggested by the original question is insufficient to see anything much. Try getting the values of counter for a whole bunch of values of n - say from zero to ten - and then graphing them (counter vs n).

  7. #7
    Junior Member
    Join Date
    Oct 2012
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Big O

    The question is not on the code , it is not meant to be used to run a program, it is a theory question to figure out the value for COUNTER when you put the values in for firstly n=2 and then n=5

Similar Threads

  1. Can't read really big files
    By Yoso14 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: September 3rd, 2012, 01:59 PM
  2. Big Integer help
    By ZekeQR in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 18th, 2012, 09:03 AM
  3. A Big Hello to everybody ot there..
    By Rituparna in forum Member Introductions
    Replies: 1
    Last Post: February 24th, 2011, 05:25 AM
  4. Adding Big Numbers
    By hoiberg in forum Java Theory & Questions
    Replies: 5
    Last Post: December 16th, 2010, 07:44 AM
  5. Big-O Question
    By Kumarrrr in forum Algorithms & Recursion
    Replies: 2
    Last Post: March 3rd, 2010, 06:46 AM