Hashing, Hashing Tables Chapter 8. Class Hierarchy.

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

Hash Tables CS 310 – Professor Roch Weiss Chapter 20 All figures marked with a chapter and section number are copyrighted © 2006 by Pearson Addison-Wesley.
CSE 1302 Lecture 23 Hashing and Hash Tables Richard Gesick.
CSCE 3400 Data Structures & Algorithm Analysis
Hashing as a Dictionary Implementation
What we learn with pleasure we never forget. Alfred Mercier Smitha N Pai.
Hashing Techniques.
Hashing CS 3358 Data Structures.
Maps, Dictionaries, Hashtables
Lecture 10 Sept 29 Goals: hashing dictionary operations general idea of hashing hash functions chaining closed hashing.
Lecture 18 Nov 3 Goals: hashing dictionary operations general idea of hashing hash functions chaining closed hashing.
Lecture 11 March 5 Goals: hashing dictionary operations general idea of hashing hash functions chaining closed hashing.
CSC 2300 Data Structures & Algorithms February 27, 2007 Chapter 5. Hashing.
1 CSE 326: Data Structures Hash Tables Autumn 2007 Lecture 14.
CSE 326: Data Structures Hashing Ben Lerner Summer 2007.
Hash Tables1 Part E Hash Tables  
CS2420: Lecture 33 Vladimir Kulyukin Computer Science Department Utah State University.
Hash Tables1 Part E Hash Tables  
Tirgul 7. Find an efficient implementation of a dynamic collection of elements with unique keys Supported Operations: Insert, Search and Delete. The keys.
CS 206 Introduction to Computer Science II 11 / 12 / 2008 Instructor: Michael Eckmann.
Lecture 10: Search Structures and Hashing
Introducing Hashing Chapter 21 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
CS 206 Introduction to Computer Science II 04 / 06 / 2009 Instructor: Michael Eckmann.
COSC 2007 Data Structures II
ICS220 – Data Structures and Algorithms Lecture 10 Dr. Ken Cosh.
1 Chapter 5 Hashing General ideas Methods of implementing the hash table Comparison among these methods Applications of hashing Compare hash tables with.
Data Structures and Algorithm Analysis Hashing Lecturer: Jing Liu Homepage:
CS 202, Spring 2003 Fundamental Structures of Computer Science II Bilkent University1 Hashing CS 202 – Fundamental Structures of Computer Science II Bilkent.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture8.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 7 Prepared by İnanç TAHRALI.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
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.
David Luebke 1 10/25/2015 CS 332: Algorithms Skip Lists Hash Tables.
Hashing Sections 10.2 – 10.3 CS 302 Dr. George Bebis.
Hashing Hashing is another method for sorting and searching data.
Hashing as a Dictionary Implementation Chapter 19.
1 Introduction to Hashing - Hash Functions Sections 5.1, 5.2, and 5.6.
Searching Given distinct keys k 1, k 2, …, k n and a collection of n records of the form »(k 1,I 1 ), (k 2,I 2 ), …, (k n, I n ) Search Problem - For key.
CS201: Data Structures and Discrete Mathematics I Hash Table.
Lecture 12COMPSCI.220.FS.T Symbol Table and Hashing A ( symbol) table is a set of table entries, ( K,V) Each entry contains: –a unique key, K,
Hashing 8 April Example Consider a situation where we want to make a list of records for students currently doing the BSU CS degree, with each.
Chapter 5: Hashing Part I - Hash Tables. Hashing  What is Hashing?  Direct Access Tables  Hash Tables 2.
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.
Hashing is a method to store data in an array so that sorting, searching, inserting and deleting data is fast. For this every record needs unique key.
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.
CHAPTER 8 SEARCHING CSEB324 DATA STRUCTURES & ALGORITHM.
Chapter 11 Hash Anshuman Razdan Div of Computing Studies
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
Hashing Fundamental Data Structures and Algorithms Margaret Reid-Miller 18 January 2005.
A Introduction to Computing II Lecture 11: Hashtables Fall Session 2000.
Hashing Suppose we want to search for a data item in a huge data record tables How long will it take? – It depends on the data structure – (unsorted) linked.
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 CSCD 326 Data Structures I Hashing. 2 Hashing Background Goal: provide a constant time complexity method of searching for stored data The best traditional.
Chapter 13 C Advanced Implementations of Tables – Hash Tables.
Hashing COMP171. Hashing 2 Hashing … * Again, a (dynamic) set of elements in which we do ‘search’, ‘insert’, and ‘delete’ n Linear ones: lists, stacks,
CS6045: Advanced Algorithms Data Structures. Hashing Tables Motivation: symbol tables –A compiler uses a symbol table to relate symbols to associated.
Searching Tables Table: sequence of (key,information) pairs (key,information) pair is a record key uniquely identifies information, so no duplicate records.
CMSC 341 Hashing Readings: Chapter 5. Announcements Midterm II on Nov 7 Review out Oct 29 HW 5 due Thursday CMSC 341 Hashing 2.
Hash Tables Ellen Walker CPSC 201 Data Structures Hiram College.
Hashing & Hash Tables. Sets/Dictionaries Set - Our best efforts to date:
CSC 413/513: Intro to Algorithms Hash Tables. ● Hash table: ■ Given a table T and a record x, with key (= symbol) and satellite data, we need to support:
TOPIC 5 ASSIGNMENT SORTING, HASH TABLES & LINKED LISTS Yerusha Nuh & Ivan Yu.
CSC 143T 1 CSC 143 Highlights of Tables and Hashing [Chapter 11 p (Tables)] [Chapter 12 p (Hashing)]
CS223 Advanced Data Structures and Algorithms
Hash Table.
CSCE 3110 Data Structures & Algorithm Analysis
CS223 Advanced Data Structures and Algorithms
Data Structures and Algorithm Analysis Hashing
Presentation transcript:

Hashing, Hashing Tables Chapter 8

Class Hierarchy

Introduction Definition: –Key: a key is a field or composite of fields that uniquely identifies an entry in a table.

Example Table of students in a course sorted by name NameYearMark Adams, Keith394 Davis, Susan175 Jordan, Ann186 Patterson, Lynn473 Williams, George165

Insert Function of ListAsArray

Find Function of ListAsArray

Insert Function of ListAsLinkedList

Find Function of ListAsLinkedList

Insert Function of SortedListAsArray

Binary Search

Hashing The implementation of hash tables is called Hashing. Hashing is a technique used for performing insertions and finds in constant average time. Efficient removal of items not required

The General Idea –Array of some fixed size, containing items.

Example

Keys and Hash Functions Each key is mapped into some number in the range 0 to TableSize-1 and placed in the appropriate cell. The mapping is called a hash function

Keys and Hash Functions Characteristics of a good hash function –Avoids collisions –Spread keys evenly in the array –Easy to compute

Avoid Collisions Ideal situation –Given a set of n<=M distinct keys {k1,k2,…,kn}, the set of hash values {h(k1),h(k2),…,h(kn)} contains no duplicates We can only try to reduce the likelihood of a collision using knowledge about the keys E.g. if we know the telephone numbers are all from the same district, so the district number will have little use in our hash function

Spreading Keys Evenly We need to know the distribution of the keys An equal number of keys should map into each array position

Ease of Computation The running time of the hash function should be O(1) (Jumping immediately to the desired record is a direct access approach, much like direct access of data on a disk)

Hashing Methods We are dealing with integer values first, K=Z The value of the hash function falls between 0 and M-1

Division Method The simplest method of hashing an integer The division method of hashing h(x) = x mod M.

Choice of M Generally, any M is good –we often choose M to be a prime number

Implementation Unsigned int const M = 1031; // a prime Unsigned int h(unsigned int x) { return x%M; }

Middle Square Method Avoid division Making use of the fact that computer does finite- precision integer arithmetic –All arithmetic is done modulo W, where W=2 w, w is the word size of the computer M=2 k, W=2 w Meaning: –Multiply x by itself, then shift to the right k bits.

Implementation unsigned int const k = 10; // M==1024 unsigned int const w = bitsizeof (unsigned int); unsigned int h (unsigned int x) { return (x * x) >> (w - k); }

Multiplication Method We multiply the key by a

Implementation unsigned int const k = 10; // M==1024 unsigned int const w = bitsizeof (unsigned int); unsigned int const a = U; unsigned int h (unsigned int x) { return (x * a) >> (w - k); } }

Hash Tables

HashTable Class Definition

Separate Chaining