06 Hashing Part 2

# 06 Hashing Part 2 - Hashing part 2 15-211 Fundamental Data...

This preview shows pages 1–10. Sign up to view the full content.

Hashing, part 2 15-211: Fundamental Data Structures and Algorithms Charlie Garrod 28 January 2010 Reading for today: Chapter 20

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Announcements HW1 programming due tonight at 11:59 Do not email us if you are using late days HW2 coming soon! Quizzes back at the end of class
3 Hash functions and hash tables “Bob” “Luis” “Kesden” “Mark” Separate chaining Open addressing and probing h ( B o b ) U L u i s 0 1 2 3 m-1 M a r k 0 1 2 3 4 5 6 7 As with long key int hash find foo link char bar url open list 0 1 2 3 m-1 !

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Expected worst-case running time “Worst-case” means worst-case inputs Not worst-case randomness Any fixed hash function h might be bad on some input Instead, average over h i in H (Not average over input) H h 2 h 3 h 1 h 99
5 When does quadratic probing work? h(k,i) = ( h(k) + i 2 ) mod m Theorem: If m is prime and λ < 0.5, then quadratic probing will always find an empty cell

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 A summary… Separate chaining is less quirky! No deletion-marking No strange behavior as λ grows Handles high load factor more gracefully Open addressing can use less space Simplifies memory management Other probe sequences, e.g. double hashing h(k,i) = h 1 (k) + ih 2 (k) (mod m ) works if m prime and h 2 (k) = 0 for all k
7 Hashing, part 2 Hashing and Java Hash functions Heuristics Universal hash functions Perfect hash functions

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
8 What does this program print? 1) a == b 2) a == b a equals b not a equals b 3) not a == b 4) not a == b a equals b not a equals b MyInteger a = new MyInteger(42); MyInteger b = new MyInteger(42); if (a == b) System.out.println(“a == b”); else System.out.println(“not a == b”); if (a.equals(b)) System.out.println(“a equals b”); else System.out.println(“not a equals b”);
9 public int hashCode() All Java Objects have .hashCode Default .hashCode might not do what you want

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This document was uploaded on 05/10/2011.

### Page1 / 36

06 Hashing Part 2 - Hashing part 2 15-211 Fundamental Data...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online