Finding the kth Smallest Elements of Two Sorted Arrays

preview_player
Показать описание
In this video, I will show you how to find the kth smallest element in two sorted arrays of length n and m in O(log n + log m) time. This generalizes the problem of finding the median.
Рекомендации по теме
Комментарии
Автор

The logic of m + n - (m + n - n//2 - m //2 - 1) <= k - 1 seems to be incorrect.
since here n = 10 and m = 9 and we stated for this case to be true we must have k>= n//2 + m//2
so:
m + n - (m + n - n//2 - m //2 - 1) <= k - 1

9 + 10 -(9 + 10 - (10//2 = 5) - (9//2 = 4) - 1) <= k-1
given that k>= n//2 + m//2 k must be k >= 9
and now in our previous statement:
9 + 10 -(9 + 10 - (10//2 = 5) - (9//2 = 4) - 1) = 19 - (19 - 5 - 4- 1) = 10 <= k which is a contradiction if k = 9 which we said was possible in the condition for this statement.

josephferraro