# Outline of Class 47: Dictionaries and Hash Tables, Continued

Held: Monday, April 27, 1998

## Administrivia

• We have an exam tomorrow. A review sheet is available (and was updated last night after I wrote the exam). Any questions on the exam? I'll spend as much time as necessary today answering review questions.
• Don't forget to sign up for the departmental picnic lunch. There's a sign-up sheet outside my door. Only sign up once!

## Handling Collisions

• What do you do when you try to insert an object into a hash table, and there's already an object at the position?
• You can put multiple objects in the same position (by using a list, a tree, or even another hash table with a different hash function).
• You can find another place in the table for the object by adding another value to the hash value.
• You can grow the hash table.
• The first method requires us to provide a dynamic data structure for each cell of the table. It also means that the lookup cost also involves searching through the structure.
• The second method requires us to do more than one "step" when looking up a value (as we might need to repeatedly skip already filled spaces).
• The third method requires us to grow the table regularly, and at a significant cost (proportional to the number of elements in the table).
• The second method also assumes a limited number of objects will be placed in the table. when you delete an object, you need to consider whether one of the objects in other cells really belonged there.
• There are a number of ways you can compute the "next" space in the second method.
• You can offset by a fixed amount.
• You can use a second function to determine the offset (making the offset object-dependent).
• You can can use a sequence of hash functions.
• ...
• Despite all this joyous freedom, I'll admit that I prefer the first method.

## Removing Elements

• Our analysis of Hash Tables to date has been based on two simple operations: lookup and insert.
• What happens if we want to remove elements? This can significantly complicate matters.
• If we've chosen the "shift into a blank space" method, what do we do when it comes time to remove elements?
• Do we shift everything back? If so, think about how far we may have to look.
• Do we leave the thing there as a blank? We might then then remove it later when it's convenient to do so.
• Do we do something totally different?
• Note also that there are different ways of specicfying "remove". We might remove the element with a particular key. We might instead remove elements based on their value. The second is obviously a much slower operation than the first (unless we've developed a special way to handle that problem - see if you can think of one).

On to Introduction to Graphs
Back to Dictionaries and Hash Tables
Outlines: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
Current position in syllabus

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.

Source text last modified Tue Jan 12 11:52:31 1999.

This page generated on Mon Jan 25 09:50:02 1999 by SiteWeaver. Validate this page.

Contact our webmaster at rebelsky@math.grin.edu