Lecture 10 Hashing.

Slides:



Advertisements
Similar presentations
Hashing.
Advertisements

Theory I Algorithm Design and Analysis (5 Hashing) Prof. Th. Ottmann.
Nov 12, 2009IAT 8001 Hash Table Bucket Sort. Nov 12, 2009IAT 8002  An array in which items are not stored consecutively - their place of storage is calculated.
Log Files. O(n) Data Structure Exercises 16.1.
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.
Look-up problem IP address did we see the IP address before?
CSE 326: Data Structures Hashing Ben Lerner Summer 2007.
Hash Tables1 Part E Hash Tables  
Lecture 10: Search Structures and Hashing
Data Structures Hashing Uri Zwick January 2014.
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.
Maps A map is an object that maps keys to values Each key can map to at most one value, and a map cannot contain duplicate keys KeyValue Map Examples Dictionaries:
Data Structures and Algorithm Analysis Hashing Lecturer: Jing Liu Homepage:
Hash Tables.
Comp 335 File Structures Hashing.
1 CSE 326: Data Structures: Hash Tables Lecture 12: Monday, Feb 3, 2003.
LECTURE 34: MAPS & HASH CSC 212 – Data Structures.
CSE 326: Data Structures Lecture #12
Chapter 5: Hashing Part I - Hash Tables. Hashing  What is Hashing?  Direct Access Tables  Hash Tables 2.
Ihab Mohammed and Safaa Alwajidi. Introduction Hash tables are dictionary structure that store objects with keys and provide very fast access. Hash table.
CSC 172 DATA STRUCTURES. SETS and HASHING  Unadvertised in-store special: SETS!  in JAVA, see Weiss 4.8  Simple Idea: Characteristic Vector  HASHING...The.
Hashing Fundamental Data Structures and Algorithms Margaret Reid-Miller 18 January 2005.
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.
CSE 326: Data Structures Lecture #14 Whoa… Good Hash, Man Steve Wolfman Winter Quarter 2000.
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.
1 Data Structures CSCI 132, Spring 2014 Lecture 33 Hash Tables.
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)]
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.
1 What is it? A side order for your eggs? A form of narcotic intake? A combination of the two?
Hashing (part 2) CSE 2011 Winter March 2018.
CSC317 Selection problem q p r Randomized‐Select(A,p,r,i)
Design & Analysis of Algorithm Hashing
CSC 172 DATA STRUCTURES.
May 3rd – Hashing & Graphs
Data Structures Using C++ 2E
Hash table CSC317 We have elements with key and satellite data
CSE373: Data Structures & Algorithms Lecture 6: Hash Tables
CSCI 210 Data Structures and Algorithms
Lecture No.43 Data Structures Dr. Sohail Aslam.
CS 332: Algorithms Hash Tables David Luebke /19/2018.
Data Structures Using C++ 2E
Hashing Exercises.
Dictionaries Dictionaries 07/27/16 16:46 07/27/16 16:46 Hash Tables 
Efficiency add remove find unsorted array O(1) O(n) sorted array
Hash functions Open addressing
Hashing CS2110 Spring 2018.
CS223 Advanced Data Structures and Algorithms
Hash Table.
Hash Table.
Hashing CS2110.
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
CSE 373 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Algorithms and Data Structures Lecture VI
Hash tables in C.
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
Pseudorandom number, Universal Hashing, Chaining and Linear-Probing
EE 312 Software Design and Implementation I
Ch Hash Tables Array or linked list Binary search trees
Ch. 13 Hash Tables  .
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
Hashing.
CS 3343: Analysis of Algorithms
Data Structures and Algorithm Analysis Hashing
Lecture 20 Hashing Amortized Analysis
EE 312 Software Design and Implementation I
Lecture-Hashing.
Presentation transcript:

Lecture 10 Hashing

Motivation: Set and Map Goal: An array whose index can be any object. Example: Dictionary Dictionary[“hash”] = “a dish of diced or chopped meat and often vegetables…” Properties: 1. Efficient lookup: Hope lookup is O(1) 2. Space: space is within constant factor to a list.

Naïve implementation of a set Method 1: Maintain a linked list. Problem: Lookup takes O(n) time. Method 2: Use a large array a[i] = 1 if i is in the set Problem: Needs huge amount of memory.

Hashing Idea: for each number, assign a random location Example: {3, 10, 3424, 643523} Store number i in a[f(i)] f(i): hash function.

Collisions Problem: want to add 123, f(123) = 4 = f(3424). (This will always happen because of pigeon hole principle) Solution: 123 and 3424 will share this location. null 10 3 3424 643523 123

Fixed Hash Function If the hash function is fixed, then it can be very slow for some bad examples. Example: We can try to find n numbers x1, x2, …, xn such that f(xi) = y for some fixed y (always possible by pigeon hole principle) Then hash table degenerates into a linked list. Solution: Use a family of random hash functions.

Universal Hash Function Hash function should be as “random” as possible. Ideally: Choose a random function out of all functions! However: cannot store a totally random function. Can use modular arithmetic to construct good hash functions! Goal: Construct a family of hash functions F, such that for any x ≠ y, we have Pr 𝑓∼𝐹 𝑓 𝑥 =𝑓 𝑦 = 1 𝑛 .

Recap: Modular Arithmetic For a prime number p, only consider numbers {0, 1, 2, 3, …, p-1} Can do addition, subtraction, multiplication the usual way (take mod p at the end). Inverse: For any integer 0 < x < p, there is an integer 0 < y < p such that 𝑥𝑦≡1(𝑚𝑜𝑑 𝑝) Example: p = 7, x = 2, then y = 4. We call y = x-1 Inverse can be computed efficiently.

Designing the Hash function Pick a prime number p, construct a hash family with p2 functions For every a, b in {0,1,2,…, p-1}, we have 𝑓 𝑎,𝑏 𝑥 =𝑎𝑥+𝑏 (𝑚𝑜𝑑 𝑝) Claim: For every x, y (x≠y), any two numbers u, v in {0, 1, 2, …, p-1}, we have Pr 𝑓 𝑥 =𝑢, 𝑓 𝑦 =𝑣 = 1 𝑝2