SUNY Geneseo Department of Computer Science


Hash Tables

Tuesday, April 23

CSci 242, Spring 2013
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture

Questions?

Hash Tables

Example (simple): build a hash table keyed by day number in year (1 - 365) containing holiday information, e.g., (1, New Years Day), (33, Ground Hog Day), etc.

Table of holiday names

            class HolidayTable

                string[ 0 .. 365 ] T

                insert( d, name )
                    if T[d] == empty
                        T[d] = name
                    else
                        T[d] = T[d] + "and" + name

                search( d )
                    return T[d]

                delete( d )
                    T[d] = empty
            hash( d )
                return d % 20

Table of pointers to list nodes

            insert( d, name )
                q = hash( d )
                InsertFront( T[q], <d,name> )
                
            search( d )
                q = hash( d )
                b = find( T[q], d )
                return name( b )

Hashing string keys

Hand out hashing homework

Next

Analysis of hashing

Read


Next Lecture