倒排列表求交集算法汇总
http://bbs.sjtu.edu.cn/bbstcon,board,Algorithm,reid,1225812893.html
我总结了一下,归纳如下: 1.1 SvS and Swapping SvS Algorithm 1 Pseudo-code for SvS SvS(set, k) 1: Sort the sets by size (|set[0]| ≤ |set[1]| ≤ . . . ≤ |set[k]|). 2: Let the smallest set s[0] be the candidate answer set. 3: for each set s[i], i = 1. . . k do initialize _[k] = 0. 4: for each set s[i], i = 1. . . k do 5: for each element e in the candidate answer set do 6: search for e in s[i] in the range l[i] to |s[i]|, 7: and update l[i] to the last position probed in the previous step. 8: if e was not found then 9: remove e from candidate answer set, 10: and advance e to the next element in the answer set. 11: end if 12: end for 13: end for 这是常用的一种算法,它首先是找出最短的两个集合,依次查找第一个集合里的元素是否 出现在第二个集合内部;Demaine考虑的Swapping_SvS和上述算法有稍微的不同,即是在每 次比较后,取包含更少元素的集合来与再下一个集合进行比较,这种算法在第一个集合和 第二个集合比较之后第二个集合反而更少的情况下效果更好,但实验表明这种情况并不多 见。1.2 Small Adaptive Algorithm 2 Pseudo-code for Small_Adaptive Small_Adaptive(set, k) 1: while no set is empty do 2: Sort the sets by increasing number of remaining elements. 3: Pick an eliminator e = set[0][0] from the smallest set. 4: elimset ← 1. 5: repeat 6: search for e in set[elimset]. 7: increment elimset; 8: until s = k or e is not found in set[elimset] 9: if s = k then 10: add e to answer. 11: end if 12: end while 这是一种混合算法,结合了Svs和Adaptive的优点。它的特点是对每个集合按未被检查过的 元素个数进行排序,从中挑出未被检查过的元素个数最少和次少的集合进行比较,找到公 有的一个元素后,再在其他集合中进行查找,有某个集合查找完毕即结束。1.3 Sequential and Random Sequential Algorithm 3 Pseudo-code for Sequential Sequential(set, k) 1: Choose an eliminator e = set[0][0], in the set elimset ← 0. 2: Consider the first set, i ← 1. 3: while the eliminator e _= ∞do 4: search in set[i] for e 5: if the search found e then 6: increase the occurrence counter. 7: if the value of occurrence counter is k then output e end if 8: end if 9: if the value of the occurrence counter is k, or e was not found then/*若计数到k或者e没有被找到*/ 10: update the eliminator to e ← set[i][succ(e)]. /*将e赋值为现在集合中下一个值*/ 11: end if 12: Consider the next set in cyclic order i ← i + 1 mod k./*循环移位地选择新的集合*/ 13: end while Barbay and Kenyon引入的,对不确定复杂度的样本查找比较好,每次在各个集合中的查找 是用快速查找。 RSequential与Sequential的区别是Sequential挑选循环中下一个集合作为下一个搜索集合 ,而RSequential则是随机挑选一个集合。1.4 Baeza-Yates and Baeza-Yates Sorted Algorithm 4 Pseudo-code for BaezaYates BaezaYates(set, k) 1: Sort the sets by size (|set[0]| ≤ |set[1]| ≤ . . . ≤ |set[k]|). 2: Let the smallest set set[0] be the candidate answer set. 3: for each set set[i], i = 1. . . k do 4: candidate ← BYintersect(candidate, set[i], 0, |candidate| − 1, 0,|set[i]| − 1) 5: sort the candidate set. 6: end forBYintersect(setA, setB, minA, maxA, minB, maxB) 1: if setA or setB are empty then return endif. 2: Let m = (minA + maxA)/2 and let medianA be the element at setA[m]. 3: Search for medianA in setB. 4: if medianA was found then 5: add medianA to result. 6: end if 7: Let r be the insertion rank of medianA in setB. 8: Solve the intersection recursively on both sides of r and m in each set. Baeza-Yates(巴伊赞-耶茨,他著有著名书籍《现代信息检索》)提出的方法,主要是利用 了分治思想,取出较短集合中的中间元素,在较长集合中搜索该元素,于是将较短和较长 集合均分为了2部分,在这2各部分中再递归搜索下去即可。注意:这样每次搜索完2个集合 ,输出的交集是无序的,因此需要将此交集再排序后,再和第3个集合进行比较搜索。 Baeza-Yates Sorted是对上述方法进行了改进,即在保存公有的元素时是按序保存的,保 存整段中间元素时必须保证前半段搜索到的中部元素已经被保存了,这样处理可以节省最 后将搜索到的交集再次排序的时间,但代价是中间处理的时候需要增加处理的细节。1.5 总结 上面所有的算法最坏情况下都有线性的时间复杂度。BaezaYates、So_BaezaYates, Small _Adaptive和SvS在集合的大小不同时有显著优势,并且Small_Adaptive是惟一一个在算法 去除集合中元素导致集合的大小动态变化时,有更大的优势;Sequential and RSequenti al 对集合大小不敏感。
转载于:https://www.cnblogs.com/bonelee/p/6593655.html
倒排列表求交集算法汇总相关推荐
- wukong引擎源码分析之索引——part 1 倒排列表本质是有序数组存储
searcher.IndexDocument(0, types.DocumentIndexData{Content: "此次百度收购将成中国互联网最大并购"}) engine.go ...
- 倒排列表压缩算法汇总——分区Elias-Fano编码貌似是最牛叉的啊!
来看看倒排索引压缩.压缩是拿CPU换IO的最重要手段之一,不论索引是放在硬盘还是内存中.索引压缩的算法有几十种,跟文本压缩不同,索引压缩算法不仅仅需要考虑压缩率,更要考虑压缩和解压性能,否则会解压太慢 ...
- java 求交集 算法_Java计算交集,差集,并集的方法示例
Java计算交集,差集,并集的方法示例 发布时间:2020-10-07 10:37:46 来源:脚本之家 阅读:106 作者:benbenkui 本文实例讲述了Java计算交集,差集,并集的方法.分享 ...
- 图解Skip List——本质是空间换时间的数据结构,在lucene的倒排列表,bigtable,hbase,cassandra的memtable,redis中sorted set中均用到...
Skip List的提出已有二十多年[Pugh, W. (1990)],却依旧应用广泛(Redis.LevelDB等).作为平衡树(AVL.红黑树.伸展树.树堆)的替代方案,虽然它性能不如平衡树稳定, ...
- python 信息检索,python信息检索代码_信息检索_倒排记录表合并算法实现(python)...
小程序描述:输入两个倒排记录表,求两个倒排记录表的交集. 倒排记录表合并算法伪代码如下所示: 功能描述: ①运行程序,看到提示"请输入词项word1:",输入某个倒排记录表的词项. ...
- 《introduction to information retrieval》信息检索学习笔记2 词项词汇和倒排记录表
第2章 词项词汇和倒排记录表 回顾建立倒排索引的主要步骤: 1.收集要索引的文档. 2.词条化文本. 3.对词条进行语言预处理,生成标准化词条. 4.建立倒排索引,索引每个词项出现的文档. 2.1文档 ...
- 《大话搜索引擎》-第一季(2)聊聊工程切分、倒排、分词
本季内容概览:大概会花费4篇左右的文章为大家讲解一个普适率80%左右的垂直搜索引擎,内容涵盖需求分析.架构设计.模块切分.各种填坑.效果评测 直至上线运行. 本篇知识点概览:工程切分.倒排.分词 一. ...
- Lucene核心数据结构——FST存词典,跳表存倒排或者roarning bitmap 见另外一个文章...
Lucene实现倒排表没有使用bitmap,为了效率,lucene使用了一些策略,具体如下: 1. 使用FST保存词典,FST可以实现快速的Seek,这种结构在当查询可以表达成自动机时(PrefixQ ...
- Lucene 倒排索fst引原理与实现
整理下几篇博客 1 Lucene 4.X 倒排索引原理与实现: (3) Term Dictionary和Index文件 (FST详细解析) https://www.cnblogs.com/forfut ...
最新文章
- python限定方法参数类型、返回值类型、变量类型等
- [leetcode] 72. 编辑距离(二维动态规划)
- PL/SQL Step By Step(三)
- mongoexport导出mongodb数据库中的数据
- linuxz指令大全
- [转载] python while循环 打印菱形
- Nginx源码分析 - HTTP模块篇 - HTTP模块的阶段处理PHASE handler(23)
- 基于Tight VNC的远程协助功能的实现
- 126 MySQL存储引擎概述
- #Linux Shell 脚本编程(10)—文本过滤(合并与分割—sort、uniq、join、cut、paste、split)
- 今天母亲节,作为程序员,我是这样表达爱的……
- 相机技术--摄像机720p、1080p、2mp、3mp、5mp;VGA, QHD, FHD, 2K,4K对应的分辨率分别是什么
- 小程序模板报价_小程序模板价格_小程序模板使用多少钱
- elementUI中级联选择器的使用
- 解决Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backslash to be include
- 华为云服务权限在哪_华为云资源IAM精细控制权限实践
- 去除噪声 matlab 论文,基于MATLAB的语音去噪开题报告
- C语言中的 |= 意思
- fst 共享后缀_关于Lucene的词典FST深入剖析
- 栈解旋(unwinding)
热门文章
- 什么是计算机系统的可信基点,基于可信基点的结构化签名比较算法.pdf
- java jtabbedpane 关闭_JTabbedPane实现关闭按钮 | 学步园
- vue webpack 访问php,实例详解vue-cli优化的webpack配置
- js弹框带传值父窗口给子框_JavaScript实现弹出子窗口并传值给父窗口
- vscode 默认初始化_VSCode设置初始化模板
- opencv机器学习线性回归_全面讲解手推实战机器学习之线性回归
- java8 求和_java8求和
- CUDA、CUDA toolkit、CUDNN、NVCC关系
- 【深度学习】Swin-Transformer和EfficientNet对比分析
- oracle SQL 命令行(三.增删改查)