The complexity of this method (in the case of good, average, worst) created by me, which calculates the intersection of two arrays is linear? O(n)
public void getInt(int[] a,int[] b){
int i=0;
int j=0;
while(i<a.length && j<b.length){
if(a[i]==b[j]){
System.out.print(a[i]+" ");
i++;j++;
}else if(a[i]<b[j]) i++;
else if(a[i]>b[j]) j++;
}
}
Yes, it will be linear.It is O(m+n), where m will be length of a and n length of b