# time complexity qustion

Printable View

• September 18th, 2012, 03:59 PM
romavolman
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 .
}

}
• September 18th, 2012, 06:24 PM
copeg
Re: time complexity qustion
Please read the forum rules. Duplicate posts are not allowed. Thread locked