[Texas PLT logo]

COMP 202: Principles of Object-Oriented Programming II

  Dictionaries & Hashing  

Dictionary

A major theme in computing is the theme of storage/retrieval/removal: store data somewhere so that it can later be retrieved and discarded if no longer needed, all of this in the most efficient manner.  The abstraction of these computing activities is embodied in the notion of what is called a dictionary, expressed in Java as an interface as follows.

 

IDictionay is an example what we call an unrestricted  access container (as opposed to restricted access container).  A simple way to implement IDictionary is to use an LRStruct.  

The problem with such an implementation is that each of the operations, insert, lookup and remove takes O(N) time, where N is the total number of elements in the dictionary.  Using a self-balanced tree will guarantee O(logN) time.  

Can we do better than that?  The answer is yes and no.  With an data structure called "hash table" coupled with an appropriate "hash function", we can achieve an amortized performance of O(1), that is constant time!

Hash Tables and Hash Functions


Hash Tables


The Problem: Collisions


Chaining


Performance


Hash Table Implementations

  Dictionaries & Hashing  

URL: http://www.clear.rice.edu/comp202/08-fall/lectures/hash/index.shtml
Copyright © 2008-2010 Mathias Ricken and Stephen Wong