CS 221 Guest lecture: Cuckoo Hashing Shannon Larson March 11, 2011.

Slides:



Advertisements
Similar presentations
Hash Tables CS 310 – Professor Roch Weiss Chapter 20 All figures marked with a chapter and section number are copyrighted © 2006 by Pearson Addison-Wesley.
Advertisements

Artificial Intelligence By Mr. Ejaz CIIT Sahiwal.
White Box and Black Box Testing Tor Stålhane. What is White Box testing White box testing is testing where we use the info available from the code of.
CSC 421: Algorithm Design & Analysis
Lecture 12: Revision Lecture Dr John Levine Algorithms and Complexity March 27th 2006.
Uninformed Search Jim Little UBC CS 322 – Search 2 September 12, 2014
A Look at Modern Dictionary Structures & Algorithms Warren Hunt.
CS 240: Data Structures Tuesday, July 24 th Searching, Hashing Graphs.
CS 206 Introduction to Computer Science II 04 / 27 / 2009 Instructor: Michael Eckmann.
Cuckoo Hashing : Hardware Implementations Adam Kirsch Michael Mitzenmacher.
HashMaps. Overview What are HashMaps? Implementing DictionaryADT with HashMaps HashMaps 2/16.
CS 1114: Data Structures – memory allocation Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Maps, Dictionaries, Hashtables
Tirgul 9 Amortized analysis Graph representation.
CS 206 Introduction to Computer Science II 12 / 05 / 2008 Instructor: Michael Eckmann.
CSC 2300 Data Structures & Algorithms February 27, 2007 Chapter 5. Hashing.
Advanced Algorithms for Massive Datasets Basics of Hashing.
CS 206 Introduction to Computer Science II 12 / 03 / 2008 Instructor: Michael Eckmann.
Introduction to Hashing CS 311 Winter, Dictionary Structure A dictionary structure has the form: (Key, Data) Dictionary structures are organized.
An Approach to Generalized Hashing Michael Klipper With Dan Blandford Guy Blelloch.
Depth-First Search Lecture 24 COMP171 Fall Graph / Slide 2 Depth-First Search (DFS) * DFS is another popular graph search strategy n Idea is similar.
Data Structures Hashing Uri Zwick January 2014.
CSE332: Data Abstractions Lecture 26: Amortized Analysis Tyler Robison Summer
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
Today’s Topics FREE Code that will Write Your PhD Thesis, a Best-Selling Novel, or Your Next Methods for Intelligently/Efficiently Searching a Space.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
MA/CSSE 473 Day 27 Hash table review Intro to string searching.
CS 206 Introduction to Computer Science II 04 / 22 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 16 / 2009 Instructor: Michael Eckmann.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
CSE 373 Data Structures and Algorithms Lecture 17: Hashing II.
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.
Data Structure & Algorithm Lecture 8 – Hashing JJCAO Most materials are stolen from Prof. Yoram Moses’s course.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
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.
Great Theoretical Ideas in Computer Science for Some.
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
1 Resolving Collision Although collisions should be avoided as much as possible, they are inevitable Need a strategy for resolving collisions. We look.
CSC 143T 1 CSC 143 Highlights of Tables and Hashing [Chapter 11 p (Tables)] [Chapter 12 p (Hashing)]
Proof of correctness of Dijkstra’s algorithm: Basically, we need to prove two claims. (1)Let S be the set of vertices for which the shortest path from.
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.
DS.H.1 Hashing Chapter 5 Overview The General Idea Hash Functions Separate Chaining Open Addressing Rehashing Extendible Hashing Application Example: Geometric.
Algorithmic Improvements for Fast Concurrent Cuckoo Hashing
May 3rd – Hashing & Graphs
CSC 421: Algorithm Design & Analysis
CSC 421: Algorithm Design & Analysis
Hash Tables 6/13/2018 Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 Cuckoo Hashing.
Week 8 - Wednesday CS221.
Final Review.
CSC 421: Algorithm Design & Analysis
Cse 373 May 15th – Iterators.
CS223 Advanced Data Structures and Algorithms
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
CS Fall 2016 (Shavlik©), Lecture 8, Week 5
Chapter 21 Hashing: Implementing Dictionaries and Sets
Open addressing.
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
Searching CLRS, Sections 9.1 – 9.3.
Advanced Implementation of Tables
CSC 421: Algorithm Design & Analysis
CSE 373: Data Structures and Algorithms
Min Heap Update E.g. remove smallest item 1. Pop off top (smallest) 3
CS223 Advanced Data Structures and Algorithms
Depth-First Search CSE 2011 Winter April 2019.
CSE 373: Data Structures and Algorithms
Linked List Intro CSCE 121.
CSC 421: Algorithm Design & Analysis
CSE 326: Data Structures Lecture #14
Assignment #2 (Assignment due: Nov. 06, 2018) v1 v2 v3 v4 v5
CSE 373: Data Structures and Algorithms
Presentation transcript:

CS 221 Guest lecture: Cuckoo Hashing Shannon Larson March 11, 2011

Learning Goals Describe the cuckoo hashing principle Analyze the space and time complexity of cuckoo hashing Apply the insert and lookup algorithms in a cuckoo hash table Construct the graph for a cuckoo table

Remember Graphs?

Graph Cycles A graph cycle is a path of edges such that the first and last vertices are the same

Recall Hashing

Cuckoo Hashing: the idea

Why is this cool? Perfect hashing guarantees – O(1) lookup, O(1) insert Cuckoo hashing guarantees – O(1) lookup – O(1) insert** Other hashing strategies can’t guarantee this! Also, it’s an option for your final project ** There’s a caveat here, but we’ll see it later

Cuckoo Hashing: Two Nests

Cuckoo Hashing: Example x

y x

z x y oh no!

Cuckoo Hashing : Example z x y NOW we’re fine!

Cuckoo Hashing : Example x y z

Why two tables? Two tables, one for each hash function Simple to visualize, simple to implement But, why two? One table works just as well! Just as simple to implement (all one table)

One Table Example x

y x

z x y oh no!

One Table Example z x y

x y z

x y z

Graph Representation How can we represent our table? Why not a graph? – Nodes are every possible table entry – Edges are inserted entries This is a directed graph Direction from current location TO alternate location

Graph Example Remember our one-table example? x y z

Infinite Insert Suppose we insert something, and we end up in an infinite loop – Or, “too many” displacements – Some pre-defined maximum based on table size

Example: Loops Remember our one-table example? x y z

Example: Loops x y z w

x y z a w

a y x z w

a y x w z

Notice what happens to the graph We keep going and going and going…

Analysis: Loops

What can we do once we get a loop? – Rebuild, same size (ok solution) – Double table size (better solution) We’ll need new hash functions for both

Analysis Lookup has O(1) time – At MOST two places to look, ever – One location per hash function Insert has amortized O(1) time – Think of this as “in the long run” – In practice we see O(1) time insert – You’ll see amortized analysis in CPSC 320 Remember the “grass and trees” analysis?

Lookup: The Code

Insert: The Code

Analysis: Load Factor

More hash functions What would this look like? We would have three tables (simple case) – One hash function per table Or, we would have two alternates (one table)

More hash functions x y z

Even better load? Currently we’ve only put one item per bucket What if we had two cells per bucket? x,w y,a z

Even better load? Currently we’ve only put one item per bucket What if we had two cells per bucket? What about collision strategies? – Round-robin (cells take turns swapping out) – FIFO (oldest resident gets kicked out)

Even better load?

Links & Resources undergrad.pdf undergrad.pdf No neat animations on the internet…yet! – Possible personal project? – Brownie points? – Pre-coop project?