{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

recitation07

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

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

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 .

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

View Full Document
6.006 Recitation Build 2008.14
Coming up next... Open addressing Karp-Rabin coming back from the dead to hunt us

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

View Full Document
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

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

View Full Document
h(k) grows up to H(k, i) where i is the attempt number first try T[H(k, 0)] H(29, 0) Collision Handling: Abstracting it Up 0 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 first try T[H(k, 0)] then T[H(k, 1)] H(29, 0) Collision Handling: Abstracting it Up 0 taken 1 taken 2 taken 3 taken 4 taken 5 taken 6 taken 7 taken 8 taken 9 taken

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

View Full Document
h(k) grows up to H(k, i) where i is the attempt H(29, 1) number first 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 0 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 first 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

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

View Full Document
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.

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 ]}