Midterm Review2.6

Midterm Review2.6 - Collision Handling Collisions occur...

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: Collision Handling Collisions occur when different elements are mapped to the same cell Separate Chaining: Let each cell in the table point to a linked list of entries that map there Separate chaining is simple, but requires additional memory outside the table 0Ø 1 2Ø 3Ø 4 CSE 2011 Prof. J. Elder - 76 - 025-612-0001 451-229-0004 981-101-0004 Last Updated: 1/7/10 10:14 AM Linear Probing Open addressing: the colliding item is placed in a different cell of the table Linear probing handles collisions by placing the colliding item in the next (circularly) available table cell Each table cell inspected is referred to as a “probe” Example: h(x) = x mod 13 Insert keys 18, 41, 22, 44, 59, 32, 31, 73, in this order 41 18 44 59 32 22 31 73 0 1 2 3 4 5 6 7 8 9 10 11 12 Colliding items lump together, so that future collisions cause a longer sequence of probes CSE 2011 Prof. J. Elder - 77 - Last Updated: 1/7/10 10:14 AM Performance of Hashing In the worst case, searches, insertions and removals on a hash table take O(n) time The worst case occurs when all the keys inserted into the map collide The load factor = n/N affects the performance of a hash table For separate chaining, performance is typically good for < 0.9. For open addressing , performance is typically good for < 0.5. java.util.HashMap maintains < 0.75 Separate chaining is typically as fast or faster than open addressing. CSE 2011 Prof. J. Elder - 78 - Last Updated: 1/7/10 10:14 AM DICTIONARIES CSE 2011 Prof. J. Elder - 79 - Last Updated: 1/7/10 10:14 AM Dictionary ADT The dictionary ADT models a searchable collection of keyelement entries Dictionary ADT methods: find(k): if the dictionary has at least one entry with key k, returns one of them, else, returns null The main operations of a dictionary are searching, inserting, and deleting items Multiple items with the same key are allowed Applications: findAll(k): returns an iterator of all entries with key k insert(k, o): inserts and returns the entry (k, o) word-definition pairs remove(e): remove the entry e from the dictionary credit card authorizations DNS mapping of host names (e.g., datastructures.net) to internet IP addresses (e.g., 128.148.34.101) entries(): returns an iterator of the entries in the dictionary size(), isEmpty() CSE 2011 Prof. J. Elder - 80 - Last Updated: 1/7/10 10:14 AM ...
View Full Document

Ask a homework question - tutors are online