recitation07

recitation07 - MIT OpenCourseWare http/ocw.mit.edu 6.006...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: MIT OpenCourseWare http://ocw.mit.edu 6.006 Introduction to Algorithms Spring 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms . 6.006 Recitation Build 2008.14 Coming up next... • Open addressing • Karp-Rabin • coming back from the dead to hunt us Open Addressing • Goal: use nothing but the table • Hoping for less code, better caching • Hashing ⇒ we must handle collisions • Solution: try another location Easy Collision handling taken taken taken taken taken here ☺ taken • h(x) = standard hash 0 function 1 • if T[h(x)] is taken 2 3 • try T[h(x)+1] h(29) ➙ 4 h(29) + 1 ➙ 5 • then T[h(x) + 2] h(29) + 2 ➙ 6 • then T[h(x) + 3] h(29) + 3 ➙ 7 8 • just like parking a car 9 • h(k) grows up to H(k, i) where i is the attempt number • frst try T[H(k, 0)] H(29, 0) ➙ Collision Handling: Abstracting it Up taken 1 taken 2 taken 3 taken 4 taken 5 taken 6 taken 7 taken 8 taken 9 taken • h(k) grows up to H(k, i) where i is the attempt H(29, 1) ➙ number • frst try T[H(k, 0)] • then T[H(k, 1)] H(29, 0) ➙ Collision Handling: Abstracting it Up taken 1 taken 2 taken 3 taken 4 taken 5 taken 6 taken 7 taken 8 taken 9 taken • h(k) grows up to H(k, i) where i is the attempt H(29, 1) ➙ number • frst try T[H(k, 0)] H(29, 2) ➙ • then T[H(k, 1)] • then T[H(k, 2)] H(29, 0) ➙ Collision Handling: Abstracting it Up taken 1 taken 2 taken 3 taken 4 taken 5 taken 6 taken 7 taken 8 taken 9 taken Collision Handling: Abstracting it Up • h(k) grows up to H(k, i) where i is the attempt number • frst try T[H(k, 0)] • then T[H(k, 1)] • then T[H(k, 2)] • stop aFter trying all H(29, 3) ➙ 0 taken H(29, 1) ➙ 1 taken H(29, 4) ➙ 2 taken H(29, 9) ➙ 3 taken H(29, 2) ➙ 4 taken H(29, 5) ➙ 5 taken H(29, 6) ➙ 6 taken H(29, 7) ➙ 7 taken H(29, 8) ➙ 8 taken H(29, 0) ➙ 9 taken Collision Handling: Abstracting it Up • H(k) = <H(k, 0), H(k, 1), H(k, 2) ... > • Linear probing, h(29) = 4, H linear (29) = ? <4, 5, 6, 7, 8, 9, 0, 1, 2, 3> • General properties? H(29, 3) ➙ 0 taken H(29, 1) ➙ 1 taken H(29, 4) ➙ 2 taken H(29, 9) ➙ 3 taken H(29, 2) ➙ 4 taken H(29, 5) ➙ 5 taken H(29, 6) ➙ 6 taken H(29, 7) ➙ 7 taken H(29, 8) ➙ 8 taken H(29, 0) ➙ 9 taken Collision Handling: Abstracting it Up • Any collision handling strategy comes to: • for key k, probe H(k,0), then H(k,1) etc....
View Full Document

This note was uploaded on 09/24/2010 for the course CS 6.006 taught by Professor Erikdemaine during the Spring '08 term at MIT.

Page1 / 37

recitation07 - MIT OpenCourseWare http/ocw.mit.edu 6.006...

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

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