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: time complexity qustion

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default time complexity qustion

    what method f do: method "f" fill emptyArr with numbers of arr1 that the method "f" don't find in arr2 and return the biggest number in arr1 that the method "f" canot
    find in arr2.
    given information - arr1.length == arr2.length, arr1 and arr2 full with whole positive numbers.

    qustion is : how to improve the time complexity of this method ???
    public int f(int[]arr1, int[]arr2, int[] emptyArr)
    {
    int length = a.length;
    int k = 0, g = 0, index = 0;
     
    for(int i=0; i < length; i++)
    {
    for(int j=0; j < length; j++)
    if(arr2[j] == arr1[i])
    break;
     
    if(j == length)
    {
    emptyArr
     
    = arr1[i];
    if(g == 0 || emptyArr
    > k) // find the max of arr1 that you don't have in arr2
    {
    k = emptyArr
    ; // max of arr1 that you don't have in arr2
    g = 1;
    }
    index++;
     
    }
     
    }
    return k; // max of arr1 that you don't have in arr2 .
    }
     
    }
    Last edited by helloworld922; September 19th, 2012 at 11:59 AM. Reason: please use [code] tags


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: time complexity qustion

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Also posted at:
    http://www.java-forums.org/advanced-...-question.html
    Last edited by Norm; September 18th, 2012 at 07:56 PM.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. time complexity qustion
    By romavolman in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 18th, 2012, 06:24 PM
  2. Binary serarch complexity. Why is it log_2(n) ?
    By u-will-neva-no in forum Java Theory & Questions
    Replies: 2
    Last Post: March 17th, 2012, 02:05 PM
  3. I need help for this time complexity measurment?
    By lulzimfazlija in forum Algorithms & Recursion
    Replies: 5
    Last Post: September 16th, 2011, 12:17 PM
  4. Using time
    By ellias2007 in forum Java Theory & Questions
    Replies: 1
    Last Post: September 4th, 2010, 08:48 AM
  5. qustion
    By vgenopoulos in forum Java Theory & Questions
    Replies: 4
    Last Post: July 27th, 2010, 11:05 PM