Lec12-13 - CS C341 I S C361 Data Structures Algorithms Dictionary Data Structures Hashing Sundar B Sundar B CSIS BITS Pilani CSIS BITS Pilani 11

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

View Full Document Right Arrow Icon
Click to edit Master subtitle style 2/7/11 Sundar B. CS C341 / I S C361 Dictionary Data Structures - Hashing Open Addressing - Analysis - Probing - Unsuccessful Find - Successful Find Bloom Filters 11
Background image of page 1

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

View Full DocumentRight Arrow Icon
2/7/11 Sundar B. Terminology The technique of chaining elements that hash into the same slots if referred to by different names: Separate Chaining for obvious reasons Open Hashing because number of elements is not limited by table size Closed Address Hashing because the location of the bucket (i.e. the address) of an element is fixed 22
Background image of page 2
2/7/11 Sundar B. Open Addressing (a.k.a. closed hashing) Fixed Space Table size m and each element can contain only one element Addressing by Hashing Probing (for a vacant location) in case of collision add(Element e, Hashtable T) // Generic procedure // e.key is key; h is hash function a = h(e.k); if T[a] is empty then { T[a]=e; return; } 33
Background image of page 3

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

View Full DocumentRight Arrow Icon
2/7/11 Sundar B. Open Addressing – Probing Schemes // m denotes table size; typically m is chosen to be prime Linear Probing: getNextAddr(a,k, j) { return (a+j) mod m; } Quadratic Probing getNextAddr(a,k,j) { return (a+j 2 ) mod m; } Exponential Probing getNextAddr(a,k,j) { return (a+2 j ) mod m; } Double Hashing getNextAddr(a,k,j) { return a+j*h2(k) mod m; } 44
Background image of page 4
2/7/11 Sundar B. Open Addressing Implementation Caveat: add as defined may not terminate! Must check whether all m locations have been probed Could be expensive! Alternatively, may use a count of non-empty locations. Will work only if the probing sequence covers all locations Define find. Similar to add: 55
Background image of page 5

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

View Full DocumentRight Arrow Icon
2/7/11 Sundar B. Open Addressing How is deletion done? Deleted slots must be marked deleted deleted flag different from empty flag for probing procedure to work find will treat deleted slots as empty slots This won’t allow re-use of deleted slots How do you recover deleted slots? add can be modified to fill in any deleted slot encountered in a probing sequence This may not cover all deleted slots 66
Background image of page 6
2/7/11 Sundar B. Open Addressing – Analysis of
Background image of page 7

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

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

This note was uploaded on 02/07/2011 for the course CS 123 taught by Professor Murali during the Spring '11 term at Birla Institute of Technology & Science, Pilani - Hyderabad.

Page1 / 23

Lec12-13 - CS C341 I S C361 Data Structures Algorithms Dictionary Data Structures Hashing Sundar B Sundar B CSIS BITS Pilani CSIS BITS Pilani 11

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

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