How to find the "joint" median of 3 sorted lists, in less than linear time?
时间: 2024-05-20 10:18:18 浏览: 16
There is no way to find the joint median of 3 sorted lists in less than linear time (O(n)) because you have to look at every element in the lists to determine the median. However, you can optimize the process by using a modified binary search algorithm.
Here's how:
1. Find the median of the first list. Let's call it m1.
2. Find the median of the second list. Let's call it m2.
3. Find the median of the third list. Let's call it m3.
4. If m1 == m2 == m3, then you have found the joint median. Return m1.
5. If m1 < m2, then discard the first half of the first list and the second half of the second list.
6. If m2 < m1, then discard the second half of the first list and the first half of the second list.
7. Repeat steps 1-6 until you find the joint median.
This modified binary search algorithm reduces the number of comparisons needed to find the joint median compared to a linear search algorithm. However, it still requires O(n) time in the worst-case scenario where all three lists have different medians.
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)