《数据结构的算法在C++中的应用》(英文版)Chapter 7 Hashing

Chapter 7 Hashing
Chapter 7 Hashing

7.1 Dictionaries a dictionary is a collection of elements; each element has a field called key, and no two elements have the same key value Operations Insert(x) insert an element with a specified key value x Search(k, x): search an element with a specified key value k, put the element into x Delete(k, x): delete an element with a specified key value k,put the element into x
7.1 Dictionaries A dictionary is a collection of elements; each element has a field called key, and no two elements have the same key value. Operations: • Insert(x): insert an element with a specified key value x • Search(k,x):search an element with a specified key value k, put the element into x • Delete(k,x):delete an element with a specified key value k,put the element into x

7.2 Linear List representation a dictionary can be maintained as an ordered Linear list(er, e2,...) e: are dictionary elements and their keys are increased from left to right We may define two classes Sorted List and Sorted Chain to facilitate this representation
7.2 Linear List Representation • A dictionary can be maintained as an ordered Linear List(e1 ,e2 ,……) • ei are dictionary elements and their keys are increased from left to right • We may define two classes Sorted List and Sorted Chain to facilitate this representation

1. SortedList Sequential Search(program 2.1 a012 The array can be ordered or unordered Time complexity ASLucC=(1+2+..tn)/n (n+1)*n/2n=(n+1)2=O(n)
1. SortedList Sequential Search(program 2.1) The array can be ordered or unordered Time complexity: ASLsucc=(1+2+……+n)/n = ((n+1)*n/2)/n=(n+1)/2=O(n) a0 a1 a2 an-1 a 0 1 2 n-1

2. Binary search It is suitable for sorted list example a:012345678 3468 10 Search x=6 low midI mid mid2 high
2.Binary Search It is suitable for sorted list example -1 0 1 3 4 6 8 10 12 a: 0 1 2 3 4 5 6 7 8 low mid1 mid3 mid2 high Search x=6

Example a:012345678 10134681012 Search x=6 midI mid 3 mid2 high 1)amid=x, found 2)amid]>x, x is in the left half of the array, search again 3)amid]x, x is in the right half of the array, search again
Example: -1 0 1 3 4 6 8 10 12 a: 0 1 2 3 4 5 6 7 8 low mid1 mid3 mid2 high Search x=6 1) a[mid]=x, found 2) a[mid]>x, x is in the left half of the array,search again 3) a[mid]<x, x is in the right half of the array,search again

Program--binary search Template int SortedList: BinarySearch(const T&x)const i int high=n-1, low=0, mid while(lowx)high=mid-1 else return mid freturn-1
Program—binary search Template int SortedList::BinarySearch(const T&x)const { int high=n-1, low=0, mid; while(lowx) high=mid-1; else return mid; }return –1; }

Analysis of binary search time complexity Best case: compare one time Worst case: no longer than the height of the binary search tree Average compare times
Analysis of binary search time complexity: • Best case: compare one time • Worst case: no longer than the height of the binary search tree • Average compare times:

2. Sorted Chain class sorted Chain(program 7-1) Search Delete(program 7-2) Insert(program 7-3)
2. SortedChain class SortedChain (program 7-1) Search ,Delete(program 7-2) Insert (program 7-3)

7.3 Hashing 1. deal hashing O() Another representation of a dictionary is to use hashing Address=hash(key), also called name-address function
7.3 Hashing 1.Ideal hashing O(1) • Another representation of a dictionary is to use hashing • Address=hash(key), also called : name-address function
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《数据结构的算法在C++中的应用》(英文版)Chapter 6 Queue.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 5 Stack.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 4 Arrays and Matrix.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 3 Linear List.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 2 Program performance.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 1 preface.ppt
- 《数据结构的算法在C++中的应用》(英文版)Textbook.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第9章 宏.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第8章 数据访问页.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第7章 建立Access报表.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第6章 Access窗体的操作.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第5章 查询的创建及应用.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第4章 建构Access数据库表.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第3章 创建Access数据库.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第2章 Access 2002应用基础.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第1章 数据库原理及基本概念.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第12章 综合实例应用.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第11章 Access数据库的管理.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)第10章 Access模块和应用程序设计.ppt
- 《Access数据库应用教程》教学资源(PPT课件讲稿)各章习题参考答案.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 8 Binary and other trees.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 9 Priority Queues.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 11 Search Trees.ppt
- 《数据结构的算法在C++中的应用》(英文版)Chapter 12 Graphs.ppt
- 四川电力职业技术学院:《ASP网络程序设计》目录.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第五章 数据库基础知识.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第二章 ASP初步.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第一章 网络程序设计概述.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第三章 ASP脚本语 VBScript.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第四章 ASP常用内部对象.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第六章 ASP数据库编程.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第八章 使用第三方组件.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第七章 文件存取组件及其它组.ppt
- 四川电力职业技术学院:《ASP网络程序设计》第一章 网络程序设计概述.ppt
- 《ASP动态网页设计》电子教案.doc
- 《ASP动态网页设计》教学大纲.doc
- 《ASP动态网页设计》教学进度表.doc
- 《ASP动态网页设计》进度计划.doc
- 《ASP动态网页设计》课程设计指导书.doc
- 《ASP动态网页设计》课程综合习题集.doc