lecture25 - COMP 250 Winter 2010 25 - maps March 15, 2010...

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

View Full Document Right Arrow Icon
COMP 250 Winter 2010 25 - maps March 15, 2010 Please print out the slides for this lecture and use them along with the text in these notes. I am not reproducing the sketches here. Maps We have seen many data structures for making a collection of objects (lists, trees, etc) and operations such as Fnding, adding and removing objects from these collections. We saw that when the objects were comparable i.e. so that an ordering was deFned, there were e±cient algorithms for many of these operations. ²or example, sorted arrays, binary search trees, and heaps made use of the ordering. Objects often have a lot of information associated with them. When we want organize objects so that we can access them e±ciently, we typically restrict ourselves to one particular piece of information. This information is called the key . It is the information that we use to organize and index the objects in the collection. As an intuitive example, take the entries in a telephone book or a personal address book. Each entry has a name that you use to index an entry. This is the key. But there is other information you want to store too. ²or a telephone book, you want an address and phone number. This other information is called the value . [ASIDE: The value might contain information that is comparable and that could be used as the key, even though it is not being used as the key. ²or example, we could organize our address book by sorting the phone numbers, and using them to look up the names of people with particular phone numbere. This is not a crazy idea. “Caller ID” basically does what I am describing: someone calls you and it uses the phone number to lookup the person’s name. ] Abstractly, suppose we have two sets: there is a set of keys K , and there is a set of values V . DeFne a map 1 to be a set of ordered pairs M = { ( k, v ) : k K, v V } ⊆ K × V, such that, for any key k in our set of possible keys, there is at most one value v such that ( k, v ) is in the map. (Mathematically, what we are calling “map” here is sometimes called a 1-1 mapping.) ²or example, let K be the set of integers and let V be the set of strings. Then the following is
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.

Page1 / 3

lecture25 - COMP 250 Winter 2010 25 - maps March 15, 2010...

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