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

Info icon This 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
Image of page 1

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

View Full Document Right 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
Image of page 2
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 !
Image of page 3

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

View Full Document Right 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
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
Image of page 5

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

View Full Document Right 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
Image of page 6
7 Hashing, part 2 Hashing and Java Hash functions Heuristics Universal hash functions Perfect hash functions
Image of page 7

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

View Full Document Right 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”);
Image of page 8
9 public int hashCode()
Image of page 9

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern