Check this code

int med1,med2;
void  func(int a[], int x1, int x2, int b[], int y1, int y2){
int midx,midy;
 if((y2-y1+1)==2)
{
med1=max(a[x1],b[y1]);
 med2=min(a[x2],b[y2]);
return;
}
 midx=(x1+x2)/2;
midy=(y1+y2)/2;
 if(a[midx]>b[midy]){
x2=x2-(midy-y1);
y1=midy;
 }else{y2=y2-(midx-x1);
x1=midx;
}
 func(a,x1,x2,b,y1,y2);
}


med1 and med2 are two medians.

On Fri, Aug 13, 2010 at 6:32 PM, Raj N <[email protected]> wrote:

> Can someone tell me what do you mean by median of 2 arrays ? Is it that the
> sorted arrays are merged and finding the median of resulting one?
>
> On Fri, Aug 13, 2010 at 1:32 AM, sachin <[email protected]> wrote:
>
>> If the ranges of the arrays are 1..n & 1..m, then we can solve it this
>> way....
>>
>> if ((m+n)&1){
>>  we can go with the method same as rahul patil's and in the condition
>> we can use count<=(m+n)/2+1, the median will be stored in res.
>> }
>> else{
>>  we can go with the method same as rahul patil's and in the condition
>> we can use count<=(m+n)/2+1 and the median in this case will be the
>> average of elements at count (m+n)/2 & at count (m+n)/2+1.So, we will
>> have to store the last element in this case.
>> }
>>
>> On Aug 11, 5:25 pm, rahul patil <[email protected]> wrote:
>> > is there any time complexity?
>> >
>> > the also can be like this
>> >
>> > char *res;
>> > char *ptr1 =arr1;
>> > char *ptr2 =arr2;
>> > int count =0, n= len(arr1) ,m=len(arr2);
>> > while(1){
>> >          while(*ptr1 > *ptr2){
>> >                   ptr2++;
>> >                   count ++;
>> >                   if( count == (n+m)/2 ){
>> >                        res=ptr1;
>> >                        break out of outer while loop;
>> >                   }
>> >          }
>> >
>> >          while(*ptr1 < *ptr2){
>> >                   ptr1++;
>> >                   count ++;
>> >                   if( count == (n+m)/2 ){
>> >                        res=ptr2;
>> >                        break out of outer while loop;
>> >                   }
>> >          }
>> >
>> > }
>> >
>> > On Aug 6, 7:20 pm, Manjunath Manohar <[email protected]> wrote:
>> >
>> > > will this work in two sorted arrays of equal length..
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected]<algogeeks%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Thanks & Regards
Nikhil Agarwal
Senior Undergraduate
Computer Science & Engineering,
National Institute Of Technology, Durgapur,India
http://tech-nikk.blogspot.com
http://beta.freshersworld.com/communities/nitd

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to