{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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
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 .
Background image of page 1

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

View Full Document Right Arrow Icon
6.006 Recitation Build 2008.14
Background image of page 2
Coming up next... Open addressing Karp-Rabin coming back from the dead to hunt us
Background image of page 3

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

View Full Document Right Arrow Icon
Open Addressing Goal: use nothing but the table Hoping for less code, better caching Hashing we must handle collisions Solution: try another location
Background image of page 4
)) )) 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
Background image of page 5

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

View Full Document Right Arrow Icon
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
Background image of page 6
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
Background image of page 7

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

View Full Document Right Arrow Icon
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
Background image of page 8
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
Background image of page 9

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

View Full Document Right Arrow Icon
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
Background image of page 10
Collision Handling: Abstracting it Up Any collision handling strategy comes to: for key k, probe H(k,0), then H(k,1) etc.
Background image of page 11

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

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

{[ snackBarMessage ]}