fractional cascading

来源:互联网 发布:define在c语言中用法 编辑:程序博客网 时间:2024/06/07 03:51

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,

L1 = 2.4, 6.4, 6.5, 8.0, 9.3
L2 = 2.3, 2.5, 2.6
L3 = 1.3, 4.4, 6.2, 6.6
L4 = 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个取一个数在加上本行数组。

M1 = 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]
M2 = 2.3[0, 1], 2.5[1, 1], 2.6[2, 1], 3.5[3, 1], 6.2[3, 3], 7.9[3, 5]
M3 = 1.3[0, 1], 3.5[1, 1], 4.4[1, 2], 6.2[2, 3], 6.6[3, 3], 7.9[4, 3]
M4 = 1.1[0, 0], 3.5[1, 0], 4.6[2, 0], 7.9[3, 0], 8.1[4, 0]
原创粉丝点击