当前位置: 首页 > news >正文

倒排列表求交集算法汇总

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 for

BYintersect(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 对集合大小不敏感。

相关文章:

  • BZOJ 4195: [Noi2015]程序自动分析 [并查集 离散化 | 种类并查集WA]
  • UIButton的titleLabel不同状态字体判断
  • STM32 Flash Download failed
  • H5+css从入门到精通
  • xpath与css的区别
  • PHP类与对象
  • malloc函数及用法
  • SQL基础操作指令
  • IP首部格式[转载]
  • Cisco配置VLAN+DHCP中继代理+NAT转发上网
  • 让angular-cli工程基于ExpressJS服务,为对接后台API做准备
  • 面空间数据中网格索引和四叉树索引的结合及优化的一种方案
  • Python学习(20):Python函数(4):关于函数式编程的内建函数
  • socket.io中文文档
  • Digester 的使用(tomcat中server.xml and web.xml 的加载)
  • Bytom交易说明(账户管理模式)
  • create-react-app项目添加less配置
  • Java基本数据类型之Number
  • Laravel 实践之路: 数据库迁移与数据填充
  • Python进阶细节
  • Python实现BT种子转化为磁力链接【实战】
  • Quartz实现数据同步 | 从0开始构建SpringCloud微服务(3)
  • SpringBoot 实战 (三) | 配置文件详解
  • SpringCloud(第 039 篇)链接Mysql数据库,通过JpaRepository编写数据库访问
  • Theano - 导数
  • 给第三方使用接口的 URL 签名实现
  • 理解在java “”i=i++;”所发生的事情
  • 算法系列——算法入门之递归分而治之思想的实现
  • 学习笔记:对象,原型和继承(1)
  • 与 ConTeXt MkIV 官方文档的接驳
  • mysql面试题分组并合并列
  • 正则表达式-基础知识Review
  • $().each和$.each的区别
  • (07)Hive——窗口函数详解
  • (floyd+补集) poj 3275
  • (Redis使用系列) Springboot 实现Redis 同数据源动态切换db 八
  • (二)Linux——Linux常用指令
  • (非本人原创)史记·柴静列传(r4笔记第65天)
  • (免费领源码)python#django#mysql公交线路查询系统85021- 计算机毕业设计项目选题推荐
  • (十三)Maven插件解析运行机制
  • (五)c52学习之旅-静态数码管
  • (终章)[图像识别]13.OpenCV案例 自定义训练集分类器物体检测
  • (转)IOS中获取各种文件的目录路径的方法
  • (转载)微软数据挖掘算法:Microsoft 时序算法(5)
  • .【机器学习】隐马尔可夫模型(Hidden Markov Model,HMM)
  • .halo勒索病毒解密方法|勒索病毒解决|勒索病毒恢复|数据库修复
  • .net core MVC 通过 Filters 过滤器拦截请求及响应内容
  • .Net Core缓存组件(MemoryCache)源码解析
  • .net MVC中使用angularJs刷新页面数据列表
  • .NET 动态调用WebService + WSE + UsernameToken
  • .NET/C# 阻止屏幕关闭,阻止系统进入睡眠状态
  • @property python知乎_Python3基础之:property
  • [100天算法】-二叉树剪枝(day 48)
  • [20181219]script使用小技巧.txt
  • [2019.3.5]BZOJ1934 [Shoi2007]Vote 善意的投票