A Hash Table with Chaining

Slides:



Advertisements
Similar presentations
1 Designing Hash Tables Sections 5.3, 5.4, Designing a hash table 1.Hash function: establishing a key with an indexed location in a hash table.
Advertisements

An Introduction to Hashing. By: Sara Kennedy Presented: November 1, 2002.
© 2004 Goodrich, Tamassia Hash Tables1  
Log Files. O(n) Data Structure Exercises 16.1.
CSE 250: Data Structures Week 12 March 31 – April 4, 2008.
1 CSE 326: Data Structures Hash Tables Autumn 2007 Lecture 14.
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
Design and Analysis of Algorithms - Chapter 71 Hashing b A very efficient method for implementing a dictionary, i.e., a set with the operations: – insert.
Hash Tables1 Part E Hash Tables  
COMP 171 Data Structures and Algorithms Tutorial 10 Hash Tables.
CSE 326 Hashing Richard Anderson (instead of Martin Tompa)
Hash Tables. Container of elements where each element has an associated key Each key is mapped to a value that determines the table cell where element.
Lecture 6 Hashing. Motivating Example Want to store a list whose elements are integers between 1 and 5 Will define an array of size 5, and if the list.
Hashing Dr. Yingwu Zhu.
Hash Tables1   © 2010 Goodrich, Tamassia.
© 2004 Goodrich, Tamassia Hash Tables1  
CS201: Data Structures and Discrete Mathematics I Hash Table.
Hashing - 2 Designing Hash Tables Sections 5.3, 5.4, 5.4, 5.6.
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.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
1 Chapter 9 Searching And Table. 2 OBJECTIVE Introduces: Basic searching concept Type of searching Hash function Collision problems.
Hash Tables ADT Data Dictionary, with two operations – Insert an item, – Search for (and retrieve) an item How should we implement a data dictionary? –
1 Hash Tables Chapter Motivation Many applications require only: –Insert –Search –Delete Examples –Symbol tables –Memory management mechanisms.
Chapter 11 (Lafore’s Book) Hash Tables Hwajung Lee.
1 What is it? A side order for your eggs? A form of narcotic intake? A combination of the two?
Algorithms Design Fall 2016 Week 6 Hash Collusion Algorithms and Binary Search Trees.
Hash Tables 1/28/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Hashing (part 2) CSE 2011 Winter March 2018.
Chapter 27 Hashing Jung Soo (Sue) Lim Cal State LA.
Hashing.
Hashing Jeff Chastine.
Hash table CSC317 We have elements with key and satellite data
Hashing CSE 2011 Winter July 2018.
Hashing - resolving collisions
Lecture 21: Hash Tables Monday, February 28, 2005.
Handling Collisions Open Addressing SNSCT-CSE/16IT201-DS.
Review Graph Directed Graph Undirected Graph Sub-Graph
Dictionaries Dictionaries 07/27/16 16:46 07/27/16 16:46 Hash Tables 
Quadratic probing Double hashing Removal and open addressing Chaining
Chapter 28 Hashing.
Richard Anderson (instead of Martin Tompa)
Hashing and Hash Tables
Hash In-Class Quiz.
תרגול 8 Hash Tables ds162-ps08 11/23/2018.
BBM 204 Algorithms Lab Recitation 5 Hash functions Sequential Chaining
Chapter 21 Hashing: Implementing Dictionaries and Sets
Collision Resolution Neil Tang 02/18/2010
Resolving collisions: Open addressing
Double hashing Removal (open addressing) Chaining
Searching Tables Table: sequence of (key,information) pairs
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.
Dictionaries 1/17/2019 7:55 AM Hash Tables   4
Hash Tables Computer Science and Engineering
Chapter 11: Hash Tables.
Hash Tables Computer Science and Engineering
Hashing Sections 10.2 – 10.3 Lecture 26 CS302 Data Structures
Hash Tables Computer Science and Engineering
Tree traversal preorder, postorder: applies to any kind of tree
Pseudorandom number, Universal Hashing, Chaining and Linear-Probing
Collision Resolution Neil Tang 02/21/2008
Chapter 11: Hash Tables.
CPSC-608 Database Systems
Collision Handling Collisions occur when different elements are mapped to the same cell.
Ch. 13 Hash Tables  .
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
Hash Tables: Associative Containers with Constant Time Operations --- On Average Consider the problem of computing the frequency of words.
Linear Hashing Example
17CS1102 DATA STRUCTURES © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED.
Dictionaries and Hash Tables
Presentation transcript:

A Hash Table with Chaining A hash table with size m = 13, h(k) = k mod 13, Store keys: 18, 41, 90, 12, 36, 28, 54, 38, 25, 10 A 1 2 3 4 5 6 7 8 9 10 11 12 54 28 41 18 10 36 25 38 12 90

A Hash Table with Chaining A hash table with size m = 11, Key Values: A S E R C H I N G X M P L Hash value: 1 8 5 7 3 9 2 A 1 2 3 4 5 6 7 8 9 10 L A A A M X N C E P E E G R H S I

Linear Probing m = 11, h(k) = k mod 11, Keys stored in the hash table: 21, 26, 5, 13, 37, 16, 15 37 1 2 3 4 5 6 7 8 9 10 13 26 5 37 21 A

Linear Probing m = 11, h(k) = k mod 11, Keys stored in the hash table: 21, 26, 5, 13, 37, 16, 15 16 1 2 3 4 5 6 7 8 9 10 13 26 5 37 16 21 A

Linear Probing m = 11, h(k) = k mod 11, Keys stored in the hash table: 21, 26, 5, 13, 37, 16, 15 15 1 2 3 4 5 6 7 8 9 10 13 26 5 37 16 15 21 A

Linear Probing m = 19, Key values: Hash values: 1 5 18 3 8 9 14 7 13 C H I N G X M P L Hash values: 1 5 18 3 8 9 14 7 13 16 12 A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A E A

Linear Probing m = 19, key hash 1 5 18 3 8 9 14 7 13 16 12 1 2 3 4 5 6 C H I N G X M P L hash 1 5 18 3 8 9 14 7 13 16 12 E 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A A C E G H I N R A

Linear Probing m = 19, key hash 1 5 18 3 8 9 14 7 13 16 12 1 2 3 4 5 6 C H I N G X M P L hash 1 5 18 3 8 9 14 7 13 16 12 X 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A A C E E G H I N R A

Linear Probing m = 19, key hash 1 5 18 3 8 9 14 7 13 16 12 1 2 3 4 5 6 C H I N G X M P L hash 1 5 18 3 8 9 14 7 13 16 12 A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A A C E E G H I X N R A

Linear Probing m = 19, key hash 1 5 18 3 8 9 14 7 13 16 12 1 2 3 4 5 6 C H I N G X M P L hash 1 5 18 3 8 9 14 7 13 16 12 E 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A A C A E E G H I X L M N P R A

Linear Probing m = 19, key hash 1 5 18 3 8 9 14 7 13 16 12 1 2 3 4 5 6 C H I N G E X A M P L E hash 1 5 18 3 8 9 14 7 13 16 12 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A A C A E E G H I X E L M N P R A

Linear Probing Inserting the element (k,x) Insert at T[h(k)] if empty else probe until space found Searching for the element (k,x) Look in T[h(k)] and all succeeding elements until there is a space or element is found Removing the element (k,x) Difficult!

Linear Probing Insert E then X; h(E) = 5, E -> 10 1 2 3 4 5 6 7 8 9 10 A 11 12 13 14 15 16 17 18 S E R C H I N G M P L Insert E then X; h(E) = 5, E -> 10 h(X) = 5, X -> 11 Now remove the E and search for X

Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 R C H I N G X M P L hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A E A

Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 H 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A C E A R A

Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 E 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A C E G A I N H R A

Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 X 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A C E G A I E N H R A

Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A C E G A I E X N H R A

Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 A 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A C E G A I E X N H R A

Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 M 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A C E G A I E X N A H R A

Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 P 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A C E M G A I E X N A H R A

Double Hashing m = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 E 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A P C E M G A I E L X N A H R A

Double Hashing N = 19, key hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 R C H I N G E X A M P L E hash1 1 5 18 3 8 9 14 7 13 16 12 hash2 7 3 6 5 8 2 1 4 h(k,i)=[(h1(k)+ixh2(k)] mod 19 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 S A P C E M G A I E L X N A H E R A