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(“Bob”) U h(“Luis”) 0 1 2 3 m-1 h(“Mark”) 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()

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.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern