lecture26 - COMP 250 Winter 2010 26 - hashing March 17,...

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

View Full Document Right Arrow Icon
COMP 250 Winter 2010 26 - hashing March 17, 2010 Today we look at a particular kind of map, sometimes called a hash map . (Java has a class HashMap for representing these kinds of maps.) Before we understand what a hash map is, though, we need to understand what hashing is. [Note: make sure you also read through the slides. There are many fgures in the slides which I have not reproduced here and which illustrate the various maps discussed in this lecture.] Hashing Suppose you have a set of keys K . DeFne a hash Function to be a mapping: h : K → { 0 , 1 , 2 , m - 1 } where m is some positive integer. SpeciFcally, for each key k K , the hash function speciFes some integer h ( k ). ±or hash functions, typically m is smaller than the number of keys in K . ±or example, if the keys are possible social insurance numbers (10 9 of them), then we might let m be 1000, rather than 10 9 . So it happens alot that two keys in K to map to the same integer. Also note that the hash function h is a mapping that is deFned on the entire set K and not just on a subset of K . (The deFnition of mapping last class allowed a mapping to only include a subset of keys.). It is very common to design hash functions by writing them as a composition of two maps. The Frst map takes keys K to a large set of integers. The second map takes the large set of integers to a small set of integers { 0 , 1 , . . ., m - 1 } . (The reasons for this will be clear by the end of the lecture.) The Frst mapping is called hash coding and the integer chosen for a key k is called the hash code for that key. The second mapping is called compression . Compression maps the hash codes to hash values . In fact, we saw two examples of hash codes last lecture. The keyObject-to-address map, and
Background image of page 1

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

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

This note was uploaded on 09/25/2011 for the course COMP 250 taught by Professor Blanchette during the Spring '08 term at McGill.

Page1 / 3

lecture26 - COMP 250 Winter 2010 26 - hashing March 17,...

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

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