在两个有序的数组中找第N个数,O(lgm+lgn)级

给定两个有序数组,利用分治策略设计一个O(lg m + lgn)时间复杂度的算法,找到它们合并后的第k大元素。通过将数组平分并比较中间元素,逐步缩小查找范围,直至找到目标元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述:

Give a divide and conquer algorithm for the following problem:
you are given two sorted lists of size m and n, and are allowed 
unit time access to the ith element of each list. Give an O(lg m + lgn) 
time algorithm for computing the kth largest element in the union of the  two lists. (For simplicity, you can assume that the elements of the 
two lists are distinct).

问题分析:

1. 把 A 平均分为前后两个部分,前部分有 x 个元素,后部分有 n-x 个元素

(由于 A 是有序的,所以后一部分的所有元素大于前一部分)。A[x] = A的

后一部分的第一个元素。

 

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值