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

1. ## 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 .
}

}