fractional cascading

本文介绍了一种称为分数级联的技术,它通过合并多个有序数组并利用附加信息来加速二分搜索过程。此方法适用于需要在多个数组中查找相同元素的情况,通过预先处理将查找时间从O(klog(n/k))降低到更优的时间复杂度。

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

fractional cascading

http://en.wikipedia.org/wiki/Fractional_cascading

 

加速binary search的方法。

用空间换时间。

假如同时有多个数组,然后在其中找某个数,一般做法是每个数组都查找过去。这样算法复杂度是 O(k log(n/k)),

As a simple example of fractional cascading, consider the following problem. We are given as input a collection of k ordered lists Li of real numbers, such that the total length Σ|Li| of all lists is n, and must process them so that we can perform binary searches for a query value q in each of the k lists. For instance, with k = 4 and n = 17,

L 1 = 2.4, 6.4, 6.5, 8.0, 9.3
L 2 = 2.3, 2.5, 2.6
L 3 = 1.3, 4.4, 6.2, 6.6
L 4 = 1.1, 3.5, 4.6, 7.9, 8.1

另外一种方法如下:

将这些数组合并到一个大数组,每个数跟着这个数在原来每个数组中的位置。

we may merge all the k lists into a single big list L, and associate with each item x of L a list of the results of searching for x in each of the smaller lists Li. If we describe an element of this merged list as x[a,b,c,d] where x is the numerical value and a, b, c, and d are the positions (the first number has position 0) of the next element at least as large as x in each of the original input lists (or the position after the end of the list if no such element exists), then we would have

L = 1.1[0,0,0,0], 1.3[0,0,0,1], 2.3[0,0,1,1], 2.4[0,1,1,1], 2.5[1,1,1,1], 2.6[1,2,1,1],
3.5[1,3,1,1], 4.4[1,3,1,2], 4.6[1,3,2,2], 6.2[1,3,2,3], 6.4[1,3,3,3], 6.5[2,3,3,3],
6.6[3,3,3,3], 7.9[3,3,4,3], 8.0[3,3,4,4], 8.1[4,3,4,4], 9.3[4,3,4,5]
这样查找一个数,只要在L上查找,就能得到该数应该在每个数组中的位置。

fractional cascading:

上一行数组是下一行数组每隔1个取一个数在加上本行数组。

M 1 = 2.4[0, 1], 2.5[1, 1], 3.5[1, 3], 6.4[1, 5], 6.5[2, 5], 7.9[3, 5], 8[3, 6], 9.3[4, 6]
M 2 = 2.3[0, 1], 2.5[1, 1], 2.6[2, 1], 3.5[3, 1], 6.2[3, 3], 7.9[3, 5]
M 3 = 1.3[0, 1], 3.5[1, 1], 4.4[1, 2], 6.2[2, 3], 6.6[3, 3], 7.9[4, 3]
M 4 = 1.1[0, 0], 3.5[1, 0], 4.6[2, 0], 7.9[3, 0], 8.1[4, 0]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值