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

Thread: time complexity qustion

  1. #1
    Junior Member
    Join Date
    Sep 2012
    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])

    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;


    return k; // max of arr1 that you don't have in arr2 .

    Last edited by romavolman; September 18th, 2012 at 04:53 PM.

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    Default Re: time complexity qustion

    Please read the forum rules. Duplicate posts are not allowed. Thread locked

Similar Threads

  1. [SOLVED] Help with time
    By usama8800 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 25th, 2012, 04:13 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. First Time
    By rayoung17 in forum Member Introductions
    Replies: 1
    Last Post: April 4th, 2011, 01:52 PM
  5. qustion
    By vgenopoulos in forum Java Theory & Questions
    Replies: 4
    Last Post: July 27th, 2010, 11:05 PM