Doubt in Median of two sorted arrays of equal size

I had a doubt in the given question -
We are given two sorted arrays of equal size and we have to find the median of them when they are merged into one. The time complexity should be O(log(n+m)).
My doubt is that why can’t we simply find the median of both the arrays and take their average? Can anyone prove this false and why so?

Counterexample:

Array 1:

1 100

Array 2:

5 6

Expected Output:

\cfrac{5 + 6}{2} = 5.5

Your Output:

\cfrac{\cfrac{1 + 100}{2} + \cfrac{5 + 6}{2}}{2}

viz., 28

Correct me if I am wrong.

2 Likes

It is because when you merge two sorted arrays then the resultant array is completely new and sorted. And the median here changes. FInding the average is not correct.

Median of Two Sorted Array of the Same Size

Check this @soumakp55 @suman_18733097

2 Likes

Thanks, bro…now got