Hash Tables Computer Science and Engineering

Slides:



Advertisements
Similar presentations
© 2004 Goodrich, Tamassia Hash Tables
Advertisements

© 2004 Goodrich, Tamassia Hash Tables
© 2004 Goodrich, Tamassia Hash Tables1  
Chapter 9: Maps, Dictionaries, Hashing Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Acknowledgement: These slides are adapted from slides provided.
Maps. Hash Tables. Dictionaries. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer 2013 © 2010 Goodrich, Tamassia.
Data Structures Lecture 12 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
Log Files. O(n) Data Structure Exercises 16.1.
Maps, Dictionaries, Hashtables
Dictionaries and Hash Tables1  
1 Chapter 9 Maps and Dictionaries. 2 A basic problem We have to store some records and perform the following: add new record add new record delete record.
© 2006 Pearson Addison-Wesley. All rights reserved13 A-1 Chapter 13 Hash Tables.
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
COMP 171 Data Structures and Algorithms Tutorial 10 Hash Tables.
Hashing General idea: Get a large array
Dictionaries 4/17/2017 3:23 PM Hash Tables  
Introducing Hashing Chapter 21 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Maps, Dictionaries, Hashing
1. 2 Problem RT&T is a large phone company, and they want to provide enhanced caller ID capability: –given a phone number, return the caller’s name –phone.
CS 221 Analysis of Algorithms Data Structures Dictionaries, Hash Tables, Ordered Dictionary and Binary Search Trees.
Hashing Table Professor Sin-Min Lee Department of Computer Science.
Hash Tables1   © 2010 Goodrich, Tamassia.
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 Hashing is another method for sorting and searching data.
© 2004 Goodrich, Tamassia Hash Tables1  
Chapter 10 Hashing. The search time of each algorithm depend on the number n of elements of the collection S of the data. A searching technique called.
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.
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 What is it? A side order for your eggs? A form of narcotic intake? A combination of the two?
Hash Maps Rem Collier Room A1.02 School of Computer Science and Informatics University College Dublin, Ireland.
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 CSE 2011 Winter July 2018.
Slides by Steve Armstrong LeTourneau University Longview, TX
Hashing Alexandra Stefan.
Dictionaries and Hash Tables
Review Graph Directed Graph Undirected Graph Sub-Graph
Dictionaries Dictionaries 07/27/16 16:46 07/27/16 16:46 Hash Tables 
© 2013 Goodrich, Tamassia, Goldwasser
Dictionaries 9/14/ :35 AM Hash Tables   4
Hash Tables 3/25/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Data Structures and Database Applications Hashing and Hashtables in C#
Hash Table.
Hash Table.
Chapter 28 Hashing.
Data Structures Maps and Hash.
Data Structures and Database Applications Hashing and Hashtables in C#
Hash Tables 11/22/2018 3:15 AM Hash Tables  1 2  3  4
Dictionaries 11/23/2018 5:34 PM Hash Tables   Hash Tables.
Dictionaries and Hash Tables
Chapter 21 Hashing: Implementing Dictionaries and Sets
Copyright © Aiman Hanna All rights reserved
Hash Tables   Maps Dictionaries 12/7/2018 5:58 AM Hash Tables  
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
Dictionaries and Hash Tables
Dictionaries 1/17/2019 7:55 AM Hash Tables   4
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
CS202 - Fundamental Structures of Computer Science II
A Hash Table with Chaining
Hash Tables Computer Science and Engineering
Hash Tables Computer Science and Engineering
Pseudorandom number, Universal Hashing, Chaining and Linear-Probing
Dictionaries 4/5/2019 1:49 AM Hash Tables  
Ch. 13 Hash Tables  .
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
Chapter 13 Hashing © 2011 Pearson Addison-Wesley. All rights reserved.
Dictionaries and Hash Tables
Presentation transcript:

Hash Tables Computer Science and Engineering Chapter 8 of Goodrich and Tomassia’s Text 2/18/2019 B. Ramamurthy

Topics Hashing Hash functions Hash Tables Collision Collision resolution Chaining, linear probing, quadratic probing, double hashing Java Hash table Example 2/18/2019 B. Ramamurthy

Hashing Concept Another approach for storing and searching elements. Used in applications where add and delete, besides search, are used. Worst case linear but can get O(1) best case. 2/18/2019 B. Ramamurthy

Hash Function A hash function h maps keys of a given type into an integer interval {0, N-1} A simple function: h(x) = x mod N A good hash function will uniformly disperse the keys in the range {0, N-1} 2/18/2019 B. Ramamurthy

Hash Table Hash table ADT: Has a hash function h Array of size N Collision occurs when two keys map to the same array index. Two major collision resolution schemes are: chaining and open addressing 2/18/2019 B. Ramamurthy

Example Item(name, ssn) where ssn is 9 digit positive integer. Hash table N = 10000. Hash function: last four digits of of x Use chaining to handle collision. 2/18/2019 B. Ramamurthy

Hash Table: Example 1 2 3 045-34-0002 . 9996 9997 9998 9999 045-35-9996 567-34-9996 2/18/2019 B. Ramamurthy

Hash Functions Usually specified as two components: Component1 called the hash code map, collects the parts of the data and maps them to integers (numeric data) H1: keys  integers Component2 called the compression map, takes the integers and maps them to 0 to N-1. H2: integers {0, N-1} 2/18/2019 B. Ramamurthy

Hash Code Maps Memory address of data Integer cast of non-numeric data: bit/byte pattern of data Sum of all components: add the ascii values of your last name Polynomials of various parts of data. 2/18/2019 B. Ramamurthy

Compression maps Reminder of division (mod) h(y) = y mod N Multiple, Add and Divide (MAD) h(y) = (a*y + b) mod N where a mod N <> 0 (otherwise everything will map to b!) 2/18/2019 B. Ramamurthy

Linear Probing Linear probing resolves collision by placing the colliding item in the next available empty cell. Each entry inspected is referred to as the “probe” Example: h(x) = x mod 13 Insert keys: 18, 41, 22, 44, 59, 32, 31, 73, in that order 2/18/2019 B. Ramamurthy

Search with linear probing: find(k) j = h(k); probe = 0; while (p < N) 2.1 c = A[j] 2.2 if (c == null) return NOT_FOUND; else if (c.key() == k) return c.element(); else j = (j+1) mod N p = p +1; 3. return NOT_FOUND; 2/18/2019 B. Ramamurthy

Double Hashing h1: primary hash function If it results in collision, resolve by applying another hash function, secondary hash function; here is an example of such a function. d(k) = q – k mod q Where q < N, Possible values of d(k) are 1,2,3,..q It cannot be 0 When collision occurs: (h(k)+j*d(k)) mod N j = 0, 1, ..N-1 2/18/2019 B. Ramamurthy

Example h(k) = k mod 13 d(k) = 7 – k mod 7 Insert 18, 41, 22, 44, 59, 32, 31, 73. 2/18/2019 B. Ramamurthy