SETS AND HASHING. SETS An un-ordered collection of values Operations (S and T are sets): S ∩ T // the intersection of S and T S U T // The Union of S.

Slides:



Advertisements
Similar presentations
The ADT Hash Table What is a table?
Advertisements

An Introduction to Hashing. By: Sara Kennedy Presented: November 1, 2002.
Hashing as a Dictionary Implementation
Appendix I Hashing. Chapter Scope Hashing, conceptually Using hashes to solve problems Hash implementations Java Foundations, 3rd Edition, Lewis/DePasquale/Chase21.
Hashing Chapters What is Hashing? A technique that determines an index or location for storage of an item in a data structure The hash function.
Arrays. Memory organization Table at right shows 16 bytes, each consisting of 8 bits Each byte has an address, shown in the column to the left
Fall 2007CS 225 Sets and Maps Chapter 9. Fall 2007CS 225 Chapter Objectives To understand the Java Map and Set interfaces and how to use them To learn.
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.
Maps & Hashing Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
1/51 Dictionaries, Tables Hashing TCSS 342 2/51 The Dictionary ADT a dictionary (table) is an abstract model of a database like a priority queue, a dictionary.
Lecture 11 March 5 Goals: hashing dictionary operations general idea of hashing hash functions chaining closed hashing.
Hashing. Searching Consider the problem of searching an array for a given value –If the array is not sorted, the search requires O(n) time If the value.
Hash Tables and Associative Containers CS-212 Dick Steflik.
Sets and Maps Chapter 9. Chapter 9: Sets and Maps2 Chapter Objectives To understand the Java Map and Set interfaces and how to use them To learn about.
1 CSE 326: Data Structures Hash Tables Autumn 2007 Lecture 14.
CS 261 – Data Structures Hash Tables Part II: Using Buckets.
Hash Tables1 Part E Hash Tables  
CS 206 Introduction to Computer Science II 11 / 12 / 2008 Instructor: Michael Eckmann.
Introducing Hashing Chapter 21 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Hashing Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
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.
CS2110 Recitation Week 8. Hashing Hashing: An implementation of a set. It provides O(1) expected time for set operations Set operations Make the set empty.
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
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.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture8.
Hash Tables1   © 2010 Goodrich, Tamassia.
Appendix E-A Hashing Modified. Chapter Scope Concept of hashing Hashing functions Collision handling – Open addressing – Buckets – Chaining Deletions.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 9: Searching Data Structures.
Prof. Amr Goneid, AUC1 CSCI 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 5. Dictionaries(2): Hash Tables.
Hashing Hashing is another method for sorting and searching data.
© 2004 Goodrich, Tamassia Hash Tables1  
Hashing as a Dictionary Implementation Chapter 19.
1 Introduction to Hashing - Hash Functions Sections 5.1, 5.2, and 5.6.
The Map ADT and Hash Tables. 2 The Map ADT  Map: An abstract data type where a value is "mapped" to a unique key  Need a key and a value to insert new.
Hashing - 2 Designing Hash Tables Sections 5.3, 5.4, 5.4, 5.6.
Chapter 11 Hash Anshuman Razdan Div of Computing Studies
“Never doubt that a small group of thoughtful, committed people can change the world. Indeed, it is the only thing that ever has.” – Margaret Meade Thought.
COMP 103 Bitsets. 2 Sets, and more Sets!  Unsorted Array  Sorted ArrayO(n) for at least one of  Linked Listcontains, add, remove  Binary Search TreeO(log.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
COSC 1030 Lecture 10 Hash Table. Topics Table Hash Concept Hash Function Resolve collision Complexity Analysis.
Hash Tables © Rick Mercer.  Outline  Discuss what a hash method does  translates a string key into an integer  Discuss a few strategies for implementing.
Chapter 13 C Advanced Implementations of Tables – Hash Tables.
1 Hashing by Adlane Habed School of Computer Science University of Windsor May 6, 2005.
Week 9 - Friday.  What did we talk about last time?  Collisions  Open addressing ▪ Linear probing ▪ Quadratic probing ▪ Double hashing  Chaining.
Searching Tables Table: sequence of (key,information) pairs (key,information) pair is a record key uniquely identifies information, so no duplicate records.
CS 261 – Data Structures Hash Tables Part II: Using Buckets.
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
TOPIC 5 ASSIGNMENT SORTING, HASH TABLES & LINKED LISTS Yerusha Nuh & Ivan Yu.
Prof. Amr Goneid, AUC1 CSCI 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 5. Dictionaries(2): Hash Tables.
Building Java Programs Generics, hashing reading: 18.1.
COMP 103 Course Review. 2 Menu  A final word on hash collisions in Open Addressing / Probing  Course Summary  What we have covered  What you should.
Sets and Maps Chapter 9.
Sections 10.5 – 10.6 Hashing.
Slides by Steve Armstrong LeTourneau University Longview, TX
Data Structures and Algorithms for Information Processing
Efficiency add remove find unsorted array O(1) O(n) sorted array
Searching.
Hash Tables Part II: Using Buckets
Hash Tables.
Searching Tables Table: sequence of (key,information) pairs
CSE 373: Data Structures and Algorithms
CSE 373 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Sets and Maps Chapter 9.
CSE 373 Separate chaining; hash codes; hash maps
Podcast Ch21a Title: Hash Functions
Extendable hashing M.B.Chandak.
Sets and Maps Chapter 7 CS 225.
Presentation transcript:

SETS AND HASHING

SETS An un-ordered collection of values Operations (S and T are sets): S ∩ T // the intersection of S and T S U T // The Union of S and T S – T // The difference of S and T S.contains(e) // True / False Optional S.add(e) S.remove(e) Implementation [discuss the big-O efficiency] (Linked) Lists Trees (preferably self-balancing: e.g. Red-Black Trees) Binary Bit Strings Hash Tables

HASH TABLES A mapping: object => hash-code(integer) Hash tables are arrays Of a fixed size n (n >> expected size) Using a hash code (modulo!) Collisions: Ideally they won't happen They will when: the (n >> expected size) condition isn't met the hashing function is poorly defined. How do we handle them? buckets at each location. My approach: open addressing / probing Other variants: Cuckoo hashing, robin hood hashing, hopscotch hashing, …

HASH FUNCTIONS Perfect hashing No collisions Not usually possible (in the general case) Usually requires some a-priori knowledge of the domain. Good hash functions Characteristics: Uniform distribution of hash values (no clustering ) Memory locations?? Every object in Java has a int hashCode() method CRC for strings / binary data

OPEN HASHING / CIRCULAR PROBING int findIndex(Object e, boolean adding) { index = hashValue % tableSize if (table[index] == desiredVal): return index; else: temp_pos = (index + 1) % tableSize while (temp_pos != index): if (table[temp_pos] == desiredVal) return temp_pos; temp_pos = (temp_pos + 1) % tableSize; raise Exception?? } # desiredVal: # null / e if adding is true # e if adding is false