计算机算法导论 第11章
更新时间:2023-09-01 00:23:01 阅读量: 教育文库 文档下载
- 计算机算法导论pdf推荐度:
- 相关推荐
计算机算法导论,第十一章
Introduction to Algorithms
III Data Structures
计算机算法导论,第十一章
Dynamic Sets
Dynamic Sets: Different from mathematical set, the sets manipulated by algorithms can grow, shrink, or otherwise change over time. Algorithms may require several different types of operations to be performed on sets.
Dictionary: A dynamic set that only supports the ability to insert elements into, delete elements from, and test membership in a set.
计算机算法导论,第十一章
Elements of a dynamic set
Typically, each element is represented by an object.
An object = Key +satellite data
Some dynamic sets presuppose that the keys are drawn from a totally ordered set
计算机算法导论,第十一章
Operations on dynamic sets
Queries: simply return information about the set
SEARCH(S, k), returns a pointer x to an element in S such that key[x] = k, or NIL if no such element belongs to S. MINIMUM(S), returns a pointer to the element of S with the smallest key. MAXIMUM(S), returns a pointer to the element of S with the largest key. SUCCESSOR(S, x), returns a pointer to the next larger element in S, or NIL if x is the maximum element. PREDECESSOR(S, x), returns a pointer to the next smaller element in S, or NIL if x is the minimum element. INSERT(S, x), augments the set S with the element pointed to by x. DELETE(S, x), given a pointer x to an element in the set S, removes x from S.4
Modifying operations: change the set.
计算机算法导论,第十一章
Overview
The time taken to execute a set operation is usually measured in terms of the size of the set. Next few lectures will focus on data structures rather than straight algorithms1.2.
3.4. 5.
Chapter 10 presents the essentials of working with simple data structures such as stacks, queues, linked lists, and rooted trees. Chapter 11 introduces hash tables, which support the dictionary operations INSERT, DELETE, and SEARCH. Chapter 12 Binary search trees Chapter 13 Red-black trees, a variant of binary search trees Chapter 14, augment red-black trees to support operations other than the basic ones5
计算机算法导论,第十一章
11 Hash Table
计算机算法导论,第十一章
Hash Tables
Motivation: symbol tables
A compiler uses a symbol table to relate symbols to associated data
Symbols: variable names, procedure names, etc. Associated data: memory location, call graph, etc.
For a symbol table (also called a dictionary), we care about search, insertion, and deletion Typically don’t care about sorted order
计算机算法导论,第十一章
Symbol-table problem
The structure we will use is a hash table
Supports all the above in O(1) expected time!8
计算机算法导论,第十一章
Hashing: Keys
consider all keys to be (possibly large) natural numbers How can we convert floats to natural numbers for hashing purposes? How can we convert ASCII strings to natural numbers for hashing purposes?
计算机算法导论,第十一章
Review
Section 11.1 discusses direct addressing Section 11.2 presents the main ideas, focusing on "chaining" as a way to handle "collisions" Section 11.3 describes how array indices can
be computed from keys using hash functions Section 11.4 looks at "open addressing," which is another way to deal with collisions Section 11.5 introduces "perfect hashing"10
计算机算法导论,第十一章
11.1 Direct-address tables
计算机算法导论,第十一章
Direct Addressing
Suppose:
The range of keys is 0..m-1 Keys are distinct Set up an array T[0..m-1] in which
The idea:
T[i] = x if x T and key[x] = i T[i] = NULL otherwise Operations take O(1) time!
This is called a direct-address table
计算机算法导论,第十一章
Direct Addressing
计算机算法导论,第十一章
Direct Addressing
DIRECT-ADDRESS-SEARCH(T, k)return T [k]
DIRECT-ADDRESS-INSERT(T, x)T[key[x]] ← x
DIRECT-ADDRESS-DELETE(T, x)T[key[x]] ← NIL
Each of these operations is fast: only O(1) time is required.14
计算机算法导论,第十一章
The Problem With Direct Addressing
Direct addressing works well when the range m of keys is relatively small But what if the keys are 32-bit integers?
Problem 1: direct-address table will have 232 entries, more than 4 billion Problem 2: even if memory is not an issue, the time to initialize the elements to NULL may be
Solution: map keys to smaller range 0..m-1 This mapping is called a hash function15
计算机算法导论,第十一章
11.2 Hash tables
计算机算法导论,第十一章
Hash tables
计算机算法导论,第十一章
Hash tablesT
U (universe of keys)k1
0h(k1) h(k4)
k4 K (actual keys)k2
k5
h(k2) = h(k5)
k3
h(k3)m-118
计算机算法导论,第十一章
Hashing: Collisions
正在阅读:
计算机算法导论 第11章09-01
猫大哥和鼠小弟作文400字06-19
美丽的夜晚作文(优秀3篇)03-26
小学四年级上册数学解题能力大PK09-22
安徽省五河县第二中学高中地理2.1.3荒漠化的防治学案(无答案)新人教版必修312-08
计算机网络(南京晓庄学院题库答案)06-29
响水县实验初级中学2013年秋学期九年级第一次英语学情调研考试试卷答案07-23
使用说明前必看08-15
中国古代诗歌散文欣赏一07-01
机械设备节能、降耗、减排措施(新编版)05-04
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- 导论
- 算法
- 计算机
- 各省招教试题
- 青岛版数学九年级下册5.2《反比例函数的图象与性质》同步练习3
- 幼儿园教育活动设计与指导复习资料
- 逾期贷款催收通知书个人
- 廉洁风险防控四项长效机制
- 安徽省2017年高级机修钳工理论考试试题
- 2017安全法规复习资料
- 英美概况复习总结(英国部分)
- “十三五”规划重点-塑料调整脚项目建议书(立项报告)
- 全国人民银行个人信用报告查询地址大全及联系方式
- 2013年上半年国产小型车市场易车指数分析报告
- 细胞程序性死亡对生物发育的意义
- 价值与价值观
- 山东国资委下属企业一共有66家
- 公司治理结构的国际比较及发展趋势研究
- 高等钢结构理论2013 第3章 塑性设计-习题修订
- (修)煤矿安全生产方针及法律法规(煤矿矿长培训)
- 小学生古诗词知识竞赛题(附答案)
- 高考复习方案(全国卷)版高考化学一轮复习第4单元非金属及其化合物听课手册新人教版
- Xilinx-fpga-CPU架构2-23-24