Ch Hash Tables Array or linked list Binary search trees

Slides:



Advertisements
Similar presentations
CS202 - Fundamental Structures of Computer Science II
Advertisements

Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Hashing Techniques.
© 2006 Pearson Addison-Wesley. All rights reserved13 A-1 Chapter 13 Hash Tables.
1 CSE 326: Data Structures Hash Tables Autumn 2007 Lecture 14.
COMP 171 Data Structures and Algorithms Tutorial 10 Hash Tables.
CS 206 Introduction to Computer Science II 11 / 12 / 2008 Instructor: Michael Eckmann.
© 2006 Pearson Addison-Wesley. All rights reserved13 B-1 Chapter 13 (continued) Advanced Implementation of Tables.
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
© 2006 Pearson Addison-Wesley. All rights reserved13 B-1 Chapter 13 (excerpts) Advanced Implementation of Tables CS102 Sections 51 and 52 Marc Smith and.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture8.
IT 60101: Lecture #151 Foundation of Computing Systems Lecture 15 Searching Algorithms.
Hashing Chapter 20. Hash Table A hash table is a data structure that allows fast find, insert, and delete operations (most of the time). The simplest.
Hashing Dr. Yingwu Zhu.
© 2006 Pearson Addison-Wesley. All rights reserved13 B-1 Chapter 13 (continued) Advanced Implementation of Tables.
1 HASHING Course teacher: Moona Kanwal. 2 Hashing Mathematical concept –To define any number as set of numbers in given interval –To cut down part of.
Hashing as a Dictionary Implementation Chapter 19.
Data Structures and Algorithms Hashing First Year M. B. Fayek CUFE 2010.
Hashing Basis Ideas A data structure that allows insertion, deletion and search in O(1) in average. A data structure that allows insertion, deletion and.
Hashing Chapter 7 Section 3. What is hashing? Hashing is using a 1-D array to implement a dictionary o This implementation is called a "hash table" Items.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
Chapter 13 C Advanced Implementations of Tables – Hash Tables.
1 Hashing by Adlane Habed School of Computer Science University of Windsor May 6, 2005.
CISC220 Fall 2009 James Atlas Dec 04: Hashing and Maps K+W Chapter 9.
Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Hashing Goal Perform inserts, deletes, and finds in constant average time Topics Hash table, hash function, collisions Collision handling Separate chaining.
Hash Tables Ellen Walker CPSC 201 Data Structures Hiram College.
CE 221 Data Structures and Algorithms
Chapter 27 Hashing Jung Soo (Sue) Lim Cal State LA.
Hashing.
Data Structures Using C++ 2E
Hashing, Hash Function, Collision & Deletion
Hash table CSC317 We have elements with key and satellite data
CSCI 210 Data Structures and Algorithms
Hashing CSE 2011 Winter July 2018.
Data Abstraction & Problem Solving with C++
School of Computer Science and Engineering
Hash Tables (Chapter 13) Part 2.
Data Structures Using C++ 2E
Hash functions Open addressing
Quadratic probing Double hashing Removal and open addressing Chaining
Advanced Associative Structures
Hash Table.
Chapter 28 Hashing.
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
Hash Tables.
Data Structures and Algorithms
Chapter 21 Hashing: Implementing Dictionaries and Sets
Dictionaries and Their Implementations
Collision Resolution Neil Tang 02/18/2010
Resolving collisions: Open addressing
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
CSCE 3110 Data Structures & Algorithm Analysis
Hash Tables and Associative Containers
Hash Tables Chapter 12.7 Wherein we throw all the data into random array slots and somehow obtain O(1) retrieval time Nyhoff, ADTs, Data Structures and.
CS202 - Fundamental Structures of Computer Science II
Advanced Implementation of Tables
Advanced Implementation of Tables
Hashing Sections 10.2 – 10.3 Lecture 26 CS302 Data Structures
Tree traversal preorder, postorder: applies to any kind of tree
Collision Resolution Neil Tang 02/21/2008
Collision Handling Collisions occur when different elements are mapped to the same cell.
Ch. 13 Hash Tables  .
DATA STRUCTURES-COLLISION TECHNIQUES
17CS1102 DATA STRUCTURES © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED.
Chapter 13 Hashing © 2011 Pearson Addison-Wesley. All rights reserved.
Collision Resolution: Open Addressing Extendible Hashing
Lecture-Hashing.
CSE 373: Data Structures and Algorithms
Presentation transcript:

Ch. 13-2 Hash Tables Array or linked list Binary search trees Overall O(n) time Binary search trees Expected O(log n)-time search, insertion, and deletion But, O(n) in the worst case Balanced binary search trees Guarantees O(log n)-time search, insertion, and deletion Red-black tree, AVL tree Balanced k-ary trees Guarantees O(log n)-time search, insertion, and deletion w/ smaller constant factor 2-3 tree, 2-3-4 tree, B-trees Hash table Expected O(1)-time search, insertion, and deletion

Stack, queue, priority queue do not support search operation i.e., do not support dictionary But, hash table does not support finding the minimum (or maximum) element Applications that need radically fast operations 119 emergent calls and locating caller’s address Air flight information system 주민등록 시스템

Figure 1 Address calculator

Figure 2 A collision

Insert tableInsert(x) { // A[ ]: hash table, x: new key to insert if (A[h(x)] is not occupied) { A[h(x)] = x; } else { Find an appropriate index i by a collision-resolution method; A[i] =x ; }

Hash Functions Toy functions Modulo arithmetic Multiplication method Selection digits h(001364825) = 35 Folding h(001364825) = 1190 Modulo arithmetic h(x) = x mod tableSize tableSize is recommended to be prime Multiplication method h(x) = (xA mod 1) * tableSize A: constant in (0, 1) tableSize is not critical, usually 2p for an integer p

Collision Resolution Collision Collision resolution The situation that two keys are mapped into the same location in the hash table Collision resolution resolves collision by a seq. of hash values h0(x), h1(x), h2(x), h3(x), …

Collision-Resolution Methods Open addressing (resolves in the array) Linear probing hi(x) = (h0(x) + i) mod tableSize Quadratic probing hi(x) = (h0(x) + i2) mod tableSize Double hashing hi(x) = (α(x) + i•β(x)) mod tableSize α(x), β(x): hash functions Separate chaining Each table[i] is maintained by a linked list

Figure 3 Linear probing hi(x) = (h0(x) + i) mod tableSize Linear probing with h(x) = x mod 101 Linear probing hi(x) = (h0(x) + i) mod tableSize bad w/ primary clustering

Figure 4 Quadratic probing hi(x) = (h0(x) + i2) mod tableSize Quadratic probing with h(x) = x mod 101 Quadratic probing hi(x) = (h0(x) + i2) mod tableSize bad w/ secondary clustering

Figure 5 Double hashing during the insertion of 58, 14, and 91 h0(14)  

Increasing the size of hash table Load factor α The rate of occupied slots in the table A high load factor harms performance We need to increase the size of hash table Increasing the hash table Roughly double the table size Rehash all the items on the new table

Figure 6 Separate chaining

The Efficiency of Hashing Approximate average # of comparisons for a search Linear probing ½(1 + 1/(1-α ) ) for a successful search ½(1 + 1/(1-α )2) for an unsuccessful search Quadratic probing and double hashing –ln (1-α) /α for a successful search 1/1-α for an unsuccessful search Separate chaining (except the access for the indexing array) 1 + α/2 for a successful search α for an unsuccessful search

The Relative Efficiency of Collision-Resolution Methods

Good Hash Functions should be easy and fast to compute should scatter the data evenly on the hash table

Observation Load factor가 낮을 때는 probing 방법들은 대체로 큰 차이가 없다. Successful search는 insertion할 당시의 궤적을 그대로 밟는다.