麻省理工学院:《算法导论》(英文版) Lecture 8 Prof charles e. leiserson

Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 8 Prof charles e. leiserson
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 8 Prof. Charles E. Leiserson

A weakness of hashing Problem: For any hash function h, a set of keys exists that can cause the average access time of a hash table to skyrocket An adversary can pick all keys from kEU: h(k)=i for some slot i IDEA: Choose the hash function at random independently of the keys Even if an adversary can see your code, he or she cannot find a bad set of keys since he or she doesn ' t know exactly which hash function will be chosen o 2001 by Charles E Leiserson Introduction to Algorithms Day 12 L8.2
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 12 L8.2 A weakness of hashing Problem: For any hash function h, a set of keys exists that can cause the average access time of a hash table to skyrocket. IDEA: Choose the hash function at random, independently of the keys. • Even if an adversary can see your code, he or she cannot find a bad set of keys, since he or she doesn’t know exactly which hash function will be chosen. • An adversary can pick all keys from {k ∈ U : h(k) = i} for some slot i

Universal hashing Definition. let u a universe of keys, and let be a finite collection of hash functions each mapping ( to (0,1,., m-1. We say 升 is universal if for allx,y∈ where x≠ we have{h∈升:h(x)=h(y)}=1H|m That is the chance of a collision th: h(x)=ho)) between x and y is 1/m, if we choose h randomly from H 升 o 2001 by Charles E Leiserson Introduction to Algorithms Day 12 L8.3
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 12 L8.3 Universal hashing Definition. Let U be a universe of keys, and let H be a finite collection of hash functions, each mapping U to {0, 1, …, m–1}. We say H is universal if for all x, y ∈ U, where x ≠ y, we have |{h ∈ H : h(x) = h(y)}| = |H|/m. That is, the chance of a collision between x and y is 1/m if we choose h randomly from H. {h : h(x) = h(y)} H |H| m

Universality is good Theorem. let h be a hash function chosen uniformly ) at random from a universal set H of hash functions. Suppose h is used to hash n arbitrary keys into the m slots of a table T. Then, for a given key x, we have E#collisions with x <n/m o 2001 by Charles E Leiserson Introduction to Algorithms Day 12 L8. 4
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 12 L8.4 Universality is good Theorem. Let h be a hash function chosen (uniformly) at random from a universal set H of hash functions. Suppose h is used to hash n arbitrary keys into the m slots of a table T. Then, for a given key x, we have E[#collisions with x] < n/m

Proof of theorem Proof. Let Cr be the random variable denoting the total number of collisions of keys in Twith x and let 1 if h(x)=h(v) 0 otherwise Note:Ecn]=1 /m and c=∑ Xy y∈7-{x} o 2001 by Charles E Leiserson Introduction to Algorithms Day 12 L8.5
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 12 L8.5 Proof of theorem Proof. Let Cx be the random variable denoting the total number of collisions of keys in T with x, and let cxy = 1 if h(x) = h(y), 0 otherwise. Note: E[cxy] = 1/m and ∑ ∈ − = y T {x} x xy C c

Proof (continued) ECx]=E∑c Take expectation y∈7-{x} of both sides o 2001 by Charles E Leiserson Introduction to Algorithms Day 12 L8.6
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 12 L8.6 Proof (continued) = ∑∈ −{ } [ ] y T x x xy E C E c • Take expectation of both sides

Proof (continued) ECx=E|∑cy·. Take expectation y∈7-{x} of both sides E Xy ]· Linearity of y∈7-{x} expectation o 2001 by Charles E Leiserson Introduction to Algorithms Day 12 L8.7
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 12 L8.7 Proof (continued) ∑ ∑ ∈ − ∈ − = = { } { } [ ] [ ] y T x xy y T x x xy E c E C E c • Linearity of expectation. • Take expectation of both sides

Proof (continued) ECx]=E∑c Take expectation y∈7-{x} of both sides ∑Ecx1]. Linearity of y∈7-{x} expectation ∑1/m E XI y∈7-{x} o 2001 by Charles E Leiserson Introduction to Algorithms Day 12 l8.8
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 12 L8.8 Proof (continued) ∑ ∑ ∑ ∈ − ∈ − ∈ − = = = { } { } { } 1/ [ ] [ ] y T x y T x xy y T x x xy m E c E C E c • E[cxy] = 1/m. • Linearity of expectation. • Take expectation of both sides

Proof (continued) ECx]=E∑ Take expectation y∈7-{x} of both sides ∑Ecy]· Linearity of ∈T-{x} expectation ∑1/m E XI =1/m y∈7-{x} gebra o 2001 by Charles E Leiserson Introduction to Algorithms Day 12 L8.9
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 12 L8.9 Proof (continued) m n m E c E C E c y T x y T x xy y T x x xy 1 1/ [ ] [ ] { } { } { } − = = = = ∑ ∑ ∑ ∈ − ∈ − ∈ − • Take expectation of both sides. • Linearity of expectation. • E[cxy] = 1/m. . • Algebra

Constructing a set of universal hash functions Let m be prime. Decompose key k into r+ 1 digits, each with value in the set (0, 1,..., m-1) That is,letk=(ko,k12…,k, Where0≤k<m Randomized strategy: Pick a=(ao, a,.,a, where each a; is chosen randomly from 0, 1,.,m-1) Define ha(k)=2a, k; mod m. DO ot product. modulo m i=0 How big is={hn}?升|=m+ REMEMBER THIS! o 2001 by Charles E Leiserson Introduction to Algorithms Day 12 L8.10
© 2001 by Charles E. Leiserson Introduction to Algorithms Day 12 L8.10 REMEMBER THIS! Constructing a set of universal hash functions Let m be prime. Decompose key k into r + 1 digits, each with value in the set {0, 1, …, m–1}. That is, let k = 〈k0, k1, …, kr〉, where 0 ≤ ki < m. Randomized strategy: Pick a = 〈a0, a1, …, ar〉 where each ai is chosen randomly from {0, 1, …, m–1}. h k a k m r i a ( ) i i mod 0 ∑ = Define = . How big is H = {ha}? |H| = mr + 1. Dot product, modulo m
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 麻省理工学院:《算法导论》(英文版) Lecture 7 Prof charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 6 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版)Lecture 5 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版)Lecture 4 Prof. charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 3 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 2 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture Prof. Charles E. Leiserson.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)实验二 波形输入与仿真实现.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)综合、设计性实验指导书.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)封面.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)附录GW48EDA系统使用说明.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)实验一 可编程ASIC使用初步.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)实验五 A/D采样电路设计.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)实验四 只读存储器设计.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)实验三 序列信号发生器与序列信号检测器的设计.pdf
- 桂林电子科技大学:《可编程ASIC原理》课程教学资源(实验指导书)实验六 数字电压表设计.pdf
- 《数字平面艺术设计》课程教学资源(试卷习题)试题库.doc
- 华中科技大学:《MATLAB语言与控制系统仿真》课程教学资源(PPT课件讲稿)第四章 控制系统的分析方法.ppt
- 华中科技大学:《MATLAB语言与控制系统仿真》课程教学资源(PPT课件讲稿)第五章 SIMULINK仿真基础.ppt
- 华中科技大学:《MATLAB语言与控制系统仿真》课程教学资源(PPT课件讲稿)第二章 matlab语言基础.ppt
- 麻省理工学院:《算法导论》(英文版) Lecture 9 Prof charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 10 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 11 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 12 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版)Lecture 13 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 14 Prof charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 15 Prof charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 16 Prof charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版)Lecture 17 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 18 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 19 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 20 Prof erik demaine.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 21 Prof charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 22 Prof charles e. leiserson.pdf
- 麻省理工学院:《算法导论》(英文版) Lecture 23 Prof charles e. leiserson.pdf
- 《计算机三级网络技术》第一章 计算机基础知识.doc
- 《计算机三级网络技术》第七章 电子商务和电子政务.doc
- 《计算机三级网络技术》第三章 局域网基础.doc
- 《计算机三级网络技术》第二章 网络基本概念.doc
- 《计算机三级网络技术》第五章 因特网基础.doc