How to find kth minimal element in the union of two sorted arrays?

Posted by Michael on Stack Overflow See other posts from Stack Overflow or by Michael
Published on 2011-01-05T18:43:59Z Indexed on 2011/01/06 18:54 UTC
Read the original article Hit count: 178

This is a homework question. They say it takes O(logN + logM) where N and M are the arrays lengths.

Let's name the arrays a and b. Obviously we can ignore all a[i] and b[i] where i > k.
First let's compare a[k/2] and b[k/2]. Let b[k/2] > a[k/2]. Therefore we can discard also all b[i], where i > k/2.

Now we have all a[i], where i < k and all b[i], where i < k/2 to find the answer.

What is the next step?

© Stack Overflow or respective owner

Related posts about arrays

Related posts about algorithm