06 Hashing Part 2

06 Hashing Part 2 - Hashing, part 2 15-211: Fundamental...

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

View Full Document Right Arrow Icon
Hashing, part 2 15-211: Fundamental Data Structures and Algorithms Charlie Garrod 28 January 2010 Reading for today: Chapter 20
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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 !
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
7 Hashing, part 2 Hashing and Java Hash functions Heuristics Universal hash functions Perfect hash functions
Background image of page 7

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

View Full DocumentRight Arrow Icon
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”);
Background image of page 8
9 public int hashCode() All Java Objects have .hashCode Default .hashCode might not do what you want
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 36

06 Hashing Part 2 - Hashing, part 2 15-211: Fundamental...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online