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[index] = arr1[i];
    if(g == 0 || emptyArr[index] > k) // find the max of arr1 that you don't have in arr2
    {
    k = emptyArr[index]; // 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 romavolman; September 18th, 2012 at 04:54 PM.


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

    Three times is twice too many. Please stick to one post, and read the forum rules which you should have done prior to posting. Thread locked as duplicate of
    http://www.javaprogrammingforums.com...y-qustion.html

Similar Threads

  1. time complexity qustion
    By romavolman in forum Java Theory & Questions
    Replies: 1
    Last Post: September 18th, 2012, 07:45 PM
  2. time complexity qustion
    By romavolman in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 18th, 2012, 06:24 PM
  3. 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
  4. I need help for this time complexity measurment?
    By lulzimfazlija in forum Algorithms & Recursion
    Replies: 5
    Last Post: September 16th, 2011, 12:17 PM
  5. qustion
    By vgenopoulos in forum Java Theory & Questions
    Replies: 4
    Last Post: July 27th, 2010, 11:05 PM