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

Thread: Big-O Notation question

  1. #1
    Member
    Join Date
    Feb 2011
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Big-O Notation question

    I am working with this bit of code for this question:

      public boolean remove (T element)
      // Removes an element e from this list such that e.equals(element)
      // and returns true; if no such element exists, returns false.
      {
        find(element);    
        if (found)
        {
          list[location] = list[numElements - 1];
          list[numElements - 1] = null;
          numElements--;  
        }
        return found;
      }

    My educated guess is that this is of type O(1) since it doesn't matter how big the input, the time taken to complete the problem will remain constant. But is my logic correct? Does the fact that there's an extra step, which is the call to a different method, find(element); , change it to O(N)?


  2. #2
    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: Big-O Notation question

    You have provided little information. What does the find method actually do? Does it look through an array? Find via a hash? We can only guess, mine being that it looks through some type of array of T objects...if this is the case then what do you think the time complexity would be?

Similar Threads

  1. [SOLVED] EVALUATION OF POSTFIX NOTATION
    By Medo Almasry in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 7th, 2011, 05:24 PM
  2. POSTFIX NOTATION USING STACKS... [EXAM IN 4 HRS HELP!!!]
    By Medo Almasry in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 23rd, 2011, 12:16 AM
  3. Parsing Scientific Notation from String
    By aussiemcgr in forum Java Theory & Questions
    Replies: 7
    Last Post: December 14th, 2010, 09:45 AM
  4. Compute the frequency count and big-oh notation for a certain code segment
    By maykel_trinidad in forum Java Theory & Questions
    Replies: 3
    Last Post: November 13th, 2009, 10:23 AM