You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Could someone tell me why input2 has to be longer in length than input1?
I did some examples by hand and this is definitely right, but I am failing to understand the logic behind it.
Is it because when input2 is longer, there is more flexibility in moving the partitions around?
if (input1.length > input2.length) { return findMedianSortedArrays(input2, input1); }
The text was updated successfully, but these errors were encountered:
It DOES NOT have to be this way. It is done this way for optimization. You can verify by commenting out those 3 lines at top and it will still work.
He is doing sort of binary search on input1, so he make sure input1 is smaller one. If both are of similar length and is not much different in length it doesn't matter. But think about skewed case when one is of length 10 vs another of length 10000. Then obviously, the median will be median of 5005th and 5006th element. If you pick longer one as first and do binary search it will take many more steps to reach final answer than if you chose smaller one for doing binary search.
Could someone tell me why input2 has to be longer in length than input1?
I did some examples by hand and this is definitely right, but I am failing to understand the logic behind it.
Is it because when input2 is longer, there is more flexibility in moving the partitions around?
if (input1.length > input2.length) { return findMedianSortedArrays(input2, input1); }
The text was updated successfully, but these errors were encountered: