CSE 250: Data Structures Week 12 March 31 – April 4, 2008.

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

Preliminaries Advantages –Hash tables can insert(), remove(), and find() with complexity close to O(1). –Relatively easy to program Disadvantages –There.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Hash Tables,
Skip List & Hashing CSE, POSTECH.
Hashing21 Hashing II: The leftovers. hashing22 Hash functions Choice of hash function can be important factor in reducing the likelihood of collisions.
Hashing Techniques.
1 Hashing (Walls & Mirrors - end of Chapter 12). 2 I hate quotations. Tell me what you know. – Ralph Waldo Emerson.
Overflow Handling An overflow occurs when the home bucket for a new pair (key, element) is full. We may handle overflows by:  Search the hash table in.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 48 Hashing.
1 CSE 326: Data Structures Hash Tables Autumn 2007 Lecture 14.
Hashing Text Read Weiss, §5.1 – 5.5 Goal Perform inserts, deletes, and finds in constant average time Topics Hash table, hash function, collisions Collision.
CS 206 Introduction to Computer Science II 11 / 17 / 2008 Instructor: Michael Eckmann.
Introduction to Hashing CS 311 Winter, Dictionary Structure A dictionary structure has the form: (Key, Data) Dictionary structures are organized.
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.
CS 206 Introduction to Computer Science II 04 / 06 / 2009 Instructor: Michael Eckmann.
Hashing 1. Def. Hash Table an array in which items are inserted according to a key value (i.e. the key value is used to determine the index of the item).
Data Structures and Algorithm Analysis Hashing Lecturer: Jing Liu Homepage:
DATA STRUCTURES AND ALGORITHMS Lecture Notes 7 Prepared by İnanç TAHRALI.
Hashing Table Professor Sin-Min Lee Department of Computer Science.
Hashing Dr. Yingwu Zhu.
Appendix E-A Hashing Modified. Chapter Scope Concept of hashing Hashing functions Collision handling – Open addressing – Buckets – Chaining Deletions.
Hashing Sections 10.2 – 10.3 CS 302 Dr. George Bebis.
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.
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.
Hashing - 2 Designing Hash Tables Sections 5.3, 5.4, 5.4, 5.6.
Data Structures and Algorithms Hashing First Year M. B. Fayek CUFE 2010.
1 Hashing - Introduction Dictionary = a dynamic set that supports the operations INSERT, DELETE, SEARCH Dictionary = a dynamic set that supports the operations.
Hash Tables CSIT 402 Data Structures II. Hashing Goal Perform inserts, deletes, and finds in constant average time Topics Hash table, hash function, collisions.
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.
Hash Table March COP 3502, UCF 1. Outline Hash Table: – Motivation – Direct Access Table – Hash Table Solutions for Collision Problem: – Open.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
CS261 Data Structures Hash Tables Open Address Hashing.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
Hashing by Rafael Jaffarove CS157b. Motivation  Fast data access  Search  Insertion  Deletion  Ideal seek time is O(1)
1 Chapter 9 Searching And Table. 2 OBJECTIVE Introduces: Basic searching concept Type of searching Hash function Collision problems.
Hashing Goal Perform inserts, deletes, and finds in constant average time Topics Hash table, hash function, collisions Collision handling Separate chaining.
Searching Tables Table: sequence of (key,information) pairs (key,information) pair is a record key uniquely identifies information, so no duplicate records.
Hash Tables Ellen Walker CPSC 201 Data Structures Hiram College.
1 Resolving Collision Although collisions should be avoided as much as possible, they are inevitable Need a strategy for resolving collisions. We look.
CS 206 Introduction to Computer Science II 04 / 08 / 2009 Instructor: Michael Eckmann.
Chapter 11 (Lafore’s Book) Hash Tables Hwajung Lee.
Chapter 27 Hashing Jung Soo (Sue) Lim Cal State LA.
Week 8 - Wednesday CS221.
Cse 373 April 24th – Hashing.
Quadratic probing Double hashing Removal and open addressing Chaining
Design and Analysis of Algorithms
Hash Table.
Chapter 28 Hashing.
Instructor: Lilian de Greef Quarter: Summer 2017
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
CSE 2331/5331 Topic 8: Hash Tables CSE 2331/5331.
Data Structures and Algorithms
Chapter 21 Hashing: Implementing Dictionaries and Sets
Collision Resolution Neil Tang 02/18/2010
Resolving collisions: Open addressing
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
Searching Tables Table: sequence of (key,information) pairs
Data Structures and Algorithms
CS202 - Fundamental Structures of Computer Science II
A Hash Table with Chaining
Tree traversal preorder, postorder: applies to any kind of tree
Overflow Handling An overflow occurs when the home bucket for a new pair (key, element) is full. We may handle overflows by: Search the hash table in some.
Overflow Handling An overflow occurs when the home bucket for a new pair (key, element) is full. We may handle overflows by: Search the hash table in some.
Collision Resolution Neil Tang 02/21/2008
Overflow Handling An overflow occurs when the home bucket for a new pair (key, element) is full. We may handle overflows by: Search the hash table in some.
17CS1102 DATA STRUCTURES © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED.
Presentation transcript:

CSE 250: Data Structures Week 12 March 31 – April 4, 2008

Announcements Project 3 due extended to April 7th Homework 4 due April 11 th Homework 5 due April 18 th Project 4 due April 25 th Final Exam May 1 st 11:45 – 2:45 Cooke 121

Week’s Topics Hashing (Key, value) pairs From the key, retrieve a value using a hash function to tell you where it will be stored in your table. Hash functions should be simple to compute, ensure that distinct keys hash to distinct values, and ideally, distribute keys evenly among the elements in the store.

Week’s Topics It is possible to have two values hash to the same location in the table. This is called a collision. What do we do in this situation? Two main strategies:  Separate Chaining  Open Addressing

Week’s Topics Separate Chaining Keep a list (think linked list) of all elements that hash to the same value What are the potential shortcomings of this approach?

Week’s Notes Open Addressing Keep looking (probing) until you find an appropriate open space to put the element you are trying to store. The probing must be systematic so that you can find the inserted element at a later time using the same process.

Week’s Notes Linear Probing If the spot you hashed to is already taken, move to the next one and so on, wrapping around to the beginning of the table if necessary until you find an available spot for insertion. Problem: primary clustering – what is it – why does it happen?

Week’s Topics Quadratic Probing Probe using a quadratic method, first look one away, then four away, then nine away… Problems involving load factor of the table and size of table – when can quadratic probing go wrong?

Week’s Topics Double hashing Use a second hash function to control the probing distance that is not necessarily linear or quadratic

Week’s Topics How do you delete from a hash table that uses probing. If you delete the element outright, you could be cutting off the search for elements that come after it – what is the strategy employed when deleting?

Week’s Notes Rehashing After the table gets too full (or there have been a significant number of deletes), we should resize the table. After resizing, you would need a new hash function and should re-hash the old values into their new places in the new, larger table.