Data Structure & Algorithm Lecture 8 – Hashing JJCAO Most materials are stolen from Prof. Yoram Moses’s course.

Slides:



Advertisements
Similar presentations
Hashing.
Advertisements

© 2004 Goodrich, Tamassia Hash Tables1  
Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Hashing21 Hashing II: The leftovers. hashing22 Hash functions Choice of hash function can be important factor in reducing the likelihood of collisions.
Log Files. O(n) Data Structure Exercises 16.1.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 18: Hash Tables.
Hashing Techniques.
Hashing CS 3358 Data Structures.
1.1 Data Structure and Algorithm Lecture 9 Hashing Topics Reference: Introduction to Algorithm by Cormen Chapter 12: Hash Tables.
Lecture 10 Sept 29 Goals: hashing dictionary operations general idea of hashing hash functions chaining closed hashing.
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.
CSE 373 Data Structures Lecture 10
© 2006 Pearson Addison-Wesley. All rights reserved13 A-1 Chapter 13 Hash Tables.
Lecture 11 March 5 Goals: hashing dictionary operations general idea of hashing hash functions chaining closed hashing.
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.
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.
COMP 171 Data Structures and Algorithms Tutorial 10 Hash Tables.
CS 206 Introduction to Computer Science II 11 / 12 / 2008 Instructor: Michael Eckmann.
Hashing General idea: Get a large array
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.
Data Structures Hashing Uri Zwick January 2014.
COSC 2007 Data Structures II
ICS220 – Data Structures and Algorithms Lecture 10 Dr. Ken Cosh.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
Spring 2015 Lecture 6: Hash Tables
Symbol Tables Symbol tables are used by compilers to keep track of information about variables functions class names type names temporary variables etc.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture8.
Hashing Table Professor Sin-Min Lee Department of Computer Science.
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.
1 Hash table. 2 Objective To learn: Hash function Linear probing Quadratic probing Chained hash table.
1 Hash table. 2 A basic problem We have to store some records and perform the following:  add new record  delete record  search a record by key Find.
Hash Tables1   © 2010 Goodrich, Tamassia.
1 Symbol Tables The symbol table contains information about –variables –functions –class names –type names –temporary variables –etc.
Comp 335 File Structures Hashing.
1 5. Abstract Data Structures & Algorithms 5.2 Static Data Structures.
Data Structures and Algorithms Lecture (Searching) Instructor: Quratulain Date: 4 and 8 December, 2009 Faculty of Computer Science, IBA.
1 Hashing - Introduction Dictionary = a dynamic set that supports the operations INSERT, DELETE, SEARCH Dictionary = a dynamic set that supports the operations.
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 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 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.
Tirgul 11 Notes Hash tables –reminder –examples –some new material.
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.
CS6045: Advanced Algorithms Data Structures. Hashing Tables Motivation: symbol tables –A compiler uses a symbol table to relate symbols to associated.
Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
Hashing TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AA Course: Data Structures Lecturer: Haim Kaplan and Uri Zwick.
Hash Tables ADT Data Dictionary, with two operations – Insert an item, – Search for (and retrieve) an item How should we implement a data dictionary? –
Hashing Goal Perform inserts, deletes, and finds in constant average time Topics Hash table, hash function, collisions Collision handling Separate chaining.
1 Data Structures CSCI 132, Spring 2014 Lecture 33 Hash Tables.
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.
TOPIC 5 ASSIGNMENT SORTING, HASH TABLES & LINKED LISTS Yerusha Nuh & Ivan Yu.
Hashing (part 2) CSE 2011 Winter March 2018.
Chapter 27 Hashing Jung Soo (Sue) Lim Cal State LA.
Hashing CSE 2011 Winter July 2018.
Data Abstraction & Problem Solving with C++
School of Computer Science and Engineering
Hash Table.
Chapter 28 Hashing.
CSE 2331/5331 Topic 8: Hash Tables CSE 2331/5331.
Chapter 21 Hashing: Implementing Dictionaries and Sets
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
Chapter 13 Hashing © 2011 Pearson Addison-Wesley. All rights reserved.
Presentation transcript:

Data Structure & Algorithm Lecture 8 – Hashing JJCAO Most materials are stolen from Prof. Yoram Moses’s course.

Heap Insert 2

Hashing Data structures we have considered – Use comparisons to find items – Good behavior is O(log n) for search and insert – log(100)=6.6 and log(100,000)=16.6 Hash tables – Support only search, insert and delete – Designed for O(1) behavior on each operation. – Efficient use of space: roughly the number of items handled. 3

Dictionary ADT 4

Terminology 5

Linked List implementation 6

Array implementation 7

Array implementation - picture 8

Hash Tables 9

Hashing - picture 10

Collisions 11

Choosing a Hash Function The actual key values matter – They often are a particular subset of U: English words I.d. numbers from certain years Variable names or keywords Phone numbers A Hash Function should: – Be easy to compute – Create few collisions: inverse should be evenly distributed not be vulnerable to non-random patterns 12

Perfect Hashing If all keys are known in advance, can sometimes design a simple one-to-one hash function. Example: 13

Division Method - the mod Hash function A common type of hash function has the form: h(key) = key mod size where size is the table size m What if size=12 and all keys are 12k+2 (2, 26, 50,…) – All keys hash to same index (lots of collisions!) – We cannot store more than one key in a cell – Must pick table size carefully: a prime number is usually a good choice for size 14

Hashing Strings 15

Resolving Collisions Chaining: Elements are stored outside the table (Table locations are pointers to "buckets") Load factor is allowed to be > 1 Open Addressing: On collision, look for another place, in the table Load factor must be < 1 16

Chaining - picture 17

Chaining Linked list at each table location The table entries are pointers to list heads Search(T,k) - search in the list at T[h(k)] Insert(T,x) - insert x at head of list at T[h(key[x])] Delete(T,x) - delete x from the list at T[h(key[x])] Running Time: Insert - O(1) 18

Open Addressing (Probing) 19

Probing Schemes 20

Hash-Insert with Probing Schemes 21

Linear Probing 22

Quadratic Probing 23

Double Hashing 24

Rules of Thumb Separate chaining is simple but wastes space Linear Probing is fast when tables are sparse Double hashing is fast but needs careful implementation 25

Universal Hashing 26

Performance of Universal hashing 27

Handling load by Rehashing 28

Rehashing Example 29

Rehashing Intuition Starting with table of size 2, double when load factor exceeds 1: 30

Amortized Analysis of Rehashing 31

Homework 4 Hw04-GuiQtScribble Deadline: 22:00, Oct. ?,