We have three case here.
1.First copy the element in new array and sort it and find median which will take O(2n(lon2n) time.
2.Second merge two sort array each of size n will take O(n+n) time and then find median.
3.Third case optimal we can simply do by comparing medians
Let see the algorithm,
median(int a1[] ,int a2[] ,int n){
int m1=median (a1,n);
int m2=median (a2,n);
if(m1=m2)
{
return m1;
}
if(m1<m2)
{
return (a1+n/2 ,a2,n-n/2);
}
else
{
return (a2+n/2 ,a1, n-n/2);
}
}
Which will take O(log n) time .