大数据数据结构和算法_查找和搜索

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

是“好”算法? must produce the same hash value.
It should be efficient to compute.
二分查找(迭代)
It should uniformly distribute the keys.
例: 将32位整数变为31位正整数并对M取模
查找与搜索
哈希是通过某种算术运算, 将键转换为数组的索引
查找与搜索
We have three primary requirements in implementing a good hash function for a
什么样的
哈希算法 given data type:
It should be deterministic—equal keys
查找与搜索
哈希表
If keys are small integers, we can use an array to implement a symbol table, by interpreting the key as an array index so that we can store the value associated with key i in array position i. wtheiscsoimnspidleemr heathshoid二ngt分h, aa查tnh找ea(xntde迭nle代ssio)mnoorfe complicated type二s o分f 查ke找ys(. W递e归re)ference key-value pairs using arrays by doing arithmetic operations to transform keys into array indices.
为什么要尽可能使Key 变换后的值HashCode 均匀分布?
二分查找(迭代)
哈希值 碰撞
查找与搜索
HashCode碰撞如何解决?
拉链法(Hashing with separate chaining)
二分查找(迭代) 二分查找(递归)
查找与搜索
哈希表的应用
• 去重(搜索引擎索词素去重)
• 分组(Map-Reduce的Shuffle)
一个健壮的索引构建引擎 需要解决节点失败问题 需要重新分配失败节点上的任务
查找与搜索
搜索引擎-分布式构建索引 Splits
First, the input data,SPLITS in our case a collection of web pages, are split into n splits where the size of the split is chosen to ensure that the work can be distributed evenly (chunks should not be too large) and efficiently (the total number of chunks we need to manage should not be too large); 16 or 64MB are good sizes in distributed indexing. Splits are not preassigned to machines, but are instead assigned by the master node on an ongoing basis: As a machine finishes processing one split, it is assigned the next one. If a machine dies or becomes a laggard due to hardware problems, the split it is working on is simply reassigned to another machine.
变通: 如何求出卡号的个数?
查找与搜索 搜索引擎-分布式构建索引
查找与搜索
搜索引擎-分布式构建索引 Master Node
One requirement for robust distributed indexing is, therefore,that we divide the work up into chunks that we can easily assign and MASTER NODE – in case of failure – reassign. A master node directs the process of assigning and reassigning tasks to individual worker nodes
T 是一棵空树. 如果TL不为空,则有TL.key Root.key. 如果TR不为空,则有TR .key Root.key. TL、TR同时也是一棵二叉搜索树.
TL、TR分别代表左右子树,Root ,代表根,key是关键字.
查找与搜索
二分查找(递归)
查找与搜索
二分查找(迭代) 二分查找(递归)
• 过滤(邮箱黑名单或白名单) 二分查找(迭代)
• 文件索引和数据库索引
二分查找(递归)
查找与搜索 字典树之 ReTrieve tree
A trie for keys "A", "to", "tea", "ted", "ten", "i", "in", and "inn".
查找与搜索
字典树之 Ternary tree
数据结构和算法
第19课 查找与搜索
查找与搜索
本课时目标: ✓基础环节:回顾二叉搜索树 ✓基础环节:实现二分查找法 ✓基础环节:理解哈希表和字典 ✓基础环节:了解字典树(Trie tree和Ternary tree) ✓扩展环节:搜索引擎为什么那么快?
查找与搜索
20
12
25
9
17
30
11
19
18
二叉搜索树(BinarySearchTree) 的索引
文档1:我,你,它 文档2:我,北,风 文档3:大,数据,我
我:文档1,文档2,文档3 你:文档1, 它:文档1 …
查找与搜索 搜索引擎-简单方式构建索引
这种方式有什么问题?
查找与搜索
查找与搜索
假设有个本文文件 里面每一行如下: <卡号 : 金额>
卡号可能 重复且不相邻 求出每个卡号的 金额总数
相关文档
最新文档