复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 05 Hash tables

Data Structures and Algorithm Xiaoqing Zheng Zhengxq@fudan.edu.cn
Data Structures and Algorithm Xiaoqing Zheng zhengxq@fudan.edu.cn

Dictionary problem Dictionary T holding n records records Operations on T. x- key[x] ● INSERT(T,x) ● DELETE(T2x) Other fields. SEARCH(T, k) containing satellite data How should the data structure T'be organized?
Dictionary problem Dictionary T holding n records: key [ x ] Other fields containing satellite data records x How should the data structure T be organized? Operations on T: y INSERT ( T, x ) y DELETE ( T, x ) y SEARCH ( T, k)

Assumptions assumptions The set of keys is K CU=(1,2, ...,u-13 Keys are distinct What can we do
Assumptions Assumptions: y The set of keys is y Keys are distinct KU u ⊆= − {1, 2, , 1} " What can we do ?

Direct access table Create a table T10..u-1 fk∈ K and key{x]=k 7[k] NIL otherwise Benefit Each operation takes constant time rawbacks The range of keys can be large 64-bit numbers(which represent 18446,744,073,709,551,616 different keys) character strings(even larger!)
Direct access table Create a table T[0 … u −1]: x if k ∈ K and key [ x] = k, NIL otherwise. T[ k] = Benefit: – Each operation takes constant time Drawbacks: – The range of keys can be large: y 64-bit numbers (which represent 18,446,744,073,709,551,616 different keys), y character strings (even larger!)

Hash functions Solution: Use a hash function h to map the universe U of all keys into 0,1 h(k1) h(k4) k k h(k2)=h(k5) K ko h(k3) When a record to be inserted maps to an already occupied slot in t a collision occurs
Hash functions Solution: Use a hash function h to map the universe U of all keys into {0, 1, …, m–1}: h ( k1) h ( k4 ) h ( k2) = h ( k5) h ( k3 ) 0 m − 1 When a record to be inserted maps to an already occupied slot in T, a collision occurs. U K k1 k2 k3 k5 k4 T

Collisions resolution by chaining Records in the same slot are linked into a list T 4968|心521 h(49)=h(86)=h(52)=i
Collisions resolution by chaining Records in the same slot are linked into a list. T i 49 68 52 / h(49) = h(86) = h(52) = i

Hash functions Designing good functions is quite nontrivial For now, we assume they exist. Namely, we assume simple uniform hashing Each key k e K of keys is equally likely to be hashed to any slot of table T, independent of where other keys are hashed
Hash functions Designing good functions is quite nontrivial For now, we assume they exist. Namely, we assume simple uniform hashing: – Each key k ∈ K of keys is equally likely to be hashed to any slot of table T, independent of where other keys are hashed

Analysis of chaining Let n be the number of keys in the table and let m be the number of slots Define the load factor of T to be a=n/m average number of keys per slot The number of elements examined during a successful search for an element x is 1 more that the number of elements that appear before x in x's list
Analysis of chaining α = n m/ Let n be the number of keys in the table, and let m be the number of slots. Define the load factor of T to be = average number of keys per slot. The number of elements examined during a successful search for an element x is 1 more that the number of elements that appear before x in x’s list

Search cost Expected time to search for a record with a given key (1+a) apply hash h search function and the list access slot Expected search time o(1)ifa=O(1 or equivalently, ifn=O(m)
Search cost Expected time to search for a record with a given key Θ(1 ) +α apply hash function and access slot search the list Expected search time = Θ(1) if = O(1), or equivalently, if n = O(m). α

Analysis of successful search Let x: denote the ith element inserted into the table for i=1, 2,,n, and let ki-keyxl For keys k, and k we define the indicator variable rh(ki=h(k,)) Under the assumption of simple uniform hashing we have pr{hn(k1)=h(k,)}=m:(
Analysis of successful search 11 1 { ( ) ( )} ( ) i j pr h k h k m mm m = =⋅ ⋅ = Let xi denote the ith element inserted into the table, for i = 1, 2, .., n, and let ki = key [ xi ]. Under the assumption of simple uniform hashing, we have: For keys ki and kj, we define the indicator variable Xij = I{ h ( ki) = h ( kj)}
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 04 Soring.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 03 Basic data structure - Elementary data structures.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 02 Divide-and-conquer design paradigm.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 01 Algorithm analysis and recurrences.pdf
- 复旦大学:《数据结构与算法设计》综合项目_Project3. All-pairs shortest path.pdf
- 复旦大学:《数据结构与算法设计》综合项目_Project2. English-Chinese dictionary based on binary search tree.pdf
- 复旦大学:《数据结构与算法设计》综合项目_Project1. Combining quicksort with insertion sort.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 8. String Matching.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 7. Single-Source Shortest Paths.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 6. Greedy Algorithms.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 5. Red-Black Tree.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 4. Binary Search Trees.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 3. Hash Tables.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 2. Divide and Conquer.pdf
- 复旦大学:《数据结构与算法设计》实验设计_Lab 1. Stack.pdf
- 复旦大学:《数据结构与算法设计》考试样卷_2009-2010年度A卷(答案).pdf
- 复旦大学:《数据结构与算法设计》考试样卷_2009-2010年度A卷(试卷).pdf
- 复旦大学:《计算机网络 Computer Networking》课程教学资源(PPT课件讲稿)移动商务介绍(概念及其特点、移动商务与电子商务、价值链及商业模式).ppt
- 复旦大学:《计算机网络 Computer Networking》课程教学资源(PPT课件讲稿)无线局域网补充删节版本.ppt
- 复旦大学:《计算机网络 Computer Networking》课程教学资源(PPT课件讲稿)移动电话通信原理(补充资料).ppt
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 06 Binary search trees.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 07 Amortized analysis.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 08 Dynamic programming.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 09 Greedy algorithms.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 10 Graph algorithms.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 11 String Matching.pdf
- 复旦大学:《数据结构与算法设计 Data Structures and Algorithm》课程英文讲义_Chapter 12 NP-complete problems.pdf
- 复旦大学:《计算机网络 Computer Networking》课程教学资源_考试样卷.doc
- 复旦大学:《计算机网络 Computer Networking》课程教学资源_各章节练习题.docx
- 复旦大学:《计算机网络 Computer Networking》课程教学资源_考试样卷.doc
- 《计算机网络》课程教学资源(参考文献)END-TO-END ARGUMENTS IN SYSTEM DESIGN.pdf
- 《计算机网络》课程教学资源(参考文献)The Design Philosophy of the DARPA Internet Protocols.pdf
- 《计算机网络》课程教学资源(参考文献)Interdomain Internet Routing.pdf
- 《计算机网络》课程教学资源(参考文献)Stable Internet Routing Without Global Coordination.pdf
- 《计算机网络》课程教学资源(参考文献)9e5f3e30-0aac-407f-b55f-4b04f28fcc05.pdf
- 《计算机网络》课程教学资源(参考文献)Congestion Avoidance and Control.pdf
- 《计算机网络》课程教学资源(参考文献)Random Early Detection Gateways for Congestion Avoidance.pdf
- 《计算机网络》课程教学资源(参考文献)Congestion Control for High Bandwidth-Delay Product Networks.pdf
- 《计算机网络》课程教学资源(参考文献)Analysis and Simulation of a Fair Queueing Algorithm.pdf
- 《计算机网络》课程教学资源(参考文献)Core-St at eless Fair Queueing:Achieving Approximately Fair Bandwidth Allocations in High Speed Networks.pdf