CSC 212 – Data Structures Lecture 26: Hash Tables.

Slides:



Advertisements
Similar presentations
CSE 1302 Lecture 23 Hashing and Hash Tables Richard Gesick.
Advertisements

ICOM 4035 – Data Structures Lecture 12 – Hashtables & Map ADT Manuel Rodriguez Martinez Electrical and Computer Engineering University of Puerto Rico,
© 2004 Goodrich, Tamassia Hash Tables1  
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.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 18: Hash Tables.
Maps, Dictionaries, Hashtables
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.
1 CSE 326: Data Structures Hash Tables Autumn 2007 Lecture 14.
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
Data Structures Hash Table (aka Dictionary) i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, Andreas Veneris, Glenn Brookshear,
CSE 373 Data Structures and Algorithms Lecture 18: Hashing III.
Dictionaries 4/17/2017 3:23 PM Hash Tables  
CS 221 Analysis of Algorithms Data Structures Dictionaries, Hash Tables, Ordered Dictionary and Binary Search Trees.
CSC 213 – Large Scale Programming. Today’s Goal  Consider what will be important when searching  Why search in first place? What is its purpose?  What.
Symbol Tables Symbol tables are used by compilers to keep track of information about variables functions class names type names temporary variables etc.
Problem of the Day  Rich old man tells his 2 children he will hold a race to decide who gets his fortune. SLOWEST  Winner is one who owns SLOWEST horse.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
LECTURE 37: ORDERED DICTIONARY CSC 212 – Data Structures.
CSE 143 Lecture 11 Maps Grammars slides created by Alyssa Harding
Hash Tables1   © 2010 Goodrich, Tamassia.
LECTURE 36: DICTIONARY CSC 212 – Data Structures.
LECTURE 34: MAPS & HASH CSC 212 – Data Structures.
CSC 212 – Data Structures Lecture 37: Course Review.
© 2004 Goodrich, Tamassia Hash Tables1  
1 Introduction to Hashing - Hash Functions Sections 5.1, 5.2, and 5.6.
LECTURE 35: COLLISIONS CSC 212 – Data Structures.
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,
1 Hashing - Introduction Dictionary = a dynamic set that supports the operations INSERT, DELETE, SEARCH Dictionary = a dynamic set that supports the operations.
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.
Author: Takdir, S.ST. © Sekolah Tinggi Ilmu Statistik.
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.
1 Joe Meehean.  List of names  Set of names  Map names as keys phone #’s as values Phil Bill Will Phil Bill Will Phil Bill Will Phil: Bill:
Hashing Fundamental Data Structures and Algorithms Margaret Reid-Miller 18 January 2005.
Hashing, Hashing Tables Chapter 8. Class Hierarchy.
Tirgul 11 Notes Hash tables –reminder –examples –some new material.
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.
Hash Tables © Rick Mercer.  Outline  Discuss what a hash method does  translates a string key into an integer  Discuss a few strategies for implementing.
CSC 212 – Data Structures Lecture 23: Iterators. Question of the Day Thieves guild states it will sell to members: lock picking kits  $0.67 each 40’
Chapter 13 C Advanced Implementations of Tables – Hash Tables.
CHAPTER 9 HASH TABLES, MAPS, AND SKIP LISTS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++,
1 the hash table. hash table A hash table consists of two major components …
CS6045: Advanced Algorithms Data Structures. Hashing Tables Motivation: symbol tables –A compiler uses a symbol table to relate symbols to associated.
Week 9 - Monday.  What did we talk about last time?  Practiced with red-black trees  AVL trees  Balanced add.
1 i206: Lecture 12: Hash Tables (Dictionaries); Intro to Recursion Marti Hearst Spring 2012.
Hash Tables ADT Data Dictionary, with two operations – Insert an item, – Search for (and retrieve) an item How should we implement a data dictionary? –
CSC 212 – Data Structures Lecture 31: Last Word On Dictionaries.
Searching Tables Table: sequence of (key,information) pairs (key,information) pair is a record key uniquely identifies information, so no duplicate records.
CSE 373: Data Structures and Algorithms Lecture 16: Hashing III 1.
1 Resolving Collision Although collisions should be avoided as much as possible, they are inevitable Need a strategy for resolving collisions. We look.
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:
CSC 143T 1 CSC 143 Highlights of Tables and Hashing [Chapter 11 p (Tables)] [Chapter 12 p (Hashing)]
CSC 212 – Data Structures Lecture 28: More Hash and Dictionaries.
CSC 213 – Large Scale Programming. Today’s Goal  Review when, where, & why we use Map s  Why Sequence -based approach causes problems  How hash can.
Lecture14: Hashing Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
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 CSE 2011 Winter July 2018.
Week 8 - Wednesday CS221.
© 2013 Goodrich, Tamassia, Goldwasser
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.
JCF Hashmap & Hashset Winter 2005 CS-2851 Dr. Mark L. Hornick.
Maps.
CS210- Lecture 17 July 12, 2005 Agenda Collision Handling
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
CS210- Lecture 15 July 7, 2005 Agenda Median Heaps Adaptable PQ
Presentation transcript:

CSC 212 – Data Structures Lecture 26: Hash Tables

Question of the Day Two English words change their pronounciation when their first letter is capitalized. What are they? Polish/polish Reading/reading

Entry Interface ADT representing search data  Each Entry is key-value pair  key is what we have and use…  … but we actually want the value public interface Entry { public K key(); public V value(); }

Map ADT Represents searchable Collections  Data items are entries (key-value pairs)  Instances map keys to values Keys contained in at most one entry  So each key mapped to at most one value Values may be in multiple entries  So many keys refer to same value Basis of searching data structures

Map Interface public interface Map extends Collection { public V put(K key, V val) throws InvalidKeyException; public V get(K key) throws InvalidKeyException; public V remove(K key) throws InvalidKeyException; public Iterable keys(); public Iterable values(); public Iterable > entries(); }

PositionList-Based Implementation PositionList holds entries in any order Independent of PositionList’s implementation  Relies on methods defined by Interface Positions Entrys 9 c 6 c 5 c 8 c PositionList Map

Map Performance Want simple & fast implementation  Google: Search speed measured in TB/s  List-based Map: get, remove, put takes O(n) time Would love to use arrays  Implementation is easy  Insertion, access, and removal in O(1) time  But ranks or array indices are ints, not K

Hashing To The Rescue For each key, hash function computes integer from 0 to N - 1  For example, h(x) = x mod N  Value h(x) is “hash value” of x Hash table stores all the entries  (Nothing to do with eateries in Amsterdam)  Really just an array of size N Goal is storing entry (k, v) at index h(k)  1 st (good) implementation of a Map

Hash Table Example Stores instances of Entry Array has 10,000 indices Hash function is h(x)  x mod 10,000 What if execute call: put( , “Ike Oh”);     … | “Jill Roe” | “Bob Dole” | “Rhi Smith” | “Jay Doe”

Collisions Name when keys hash to same index Ideal hash spreads out equally and evenly  Limit/avoid collisions  But also want to keep table small But good hash hard to find  Depends on what you have to work with  Even harder to make a good hash Could try to work with collisions

Bucket Arrays Each item in array is itself a List “Chain” whenever there is a collision  Nothing to do with road rage  Instead, just add new Entry onto List

Bucket Arrays But what if have really bad hash?  Suppose always hash to same index All entries now in single List  Back to O(n) execution times  (Also get bad case of the munchies)

Your Turn Get back into groups and do activity

Before Next Lecture… Keep up with your reading! Complete Week #10 Assignment Review Programming Assignment #3