This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Unit CL Basic Counting and Listing Section 1: Lists with Repetitions We begin with some matters of terminology and notation. Two words that we shall often use are set and list . (Lists are also called strings .) Both words refer to collections of objects. There is no standard notation for lists. Some of those in use are apple banana pear peach apple , banana , pear , peach and (apple , banana , pear , peach) . The notation for sets is standard: the items are separated by commas and surrounded by curly brackets as in { apple , banana , pear , peach } . The curly bracket notation for sets is so well established that you can normally assume it means a set — but beware, some mathematical software systems use {} (curly brackets) for lists. What is the difference between a set and a list? “Set” means a collection of distinct objects in which the order doesn’t matter. Thus { apple , peach , pear } and { peach , apple , pear } are the same sets, and the set { apple , peach , apple } is the same as the set { apple , peach } . In other words, repeated elements are treated as if they occurred only once. Thus two sets are the same if and only if each element that is in one set is in both. In a list, order is important and repeated objects are usually allowed. Thus (apple , peach) (peach , apple) and (apple , peach , apple) are three different lists. Two lists are the same if and only if they have exactly the same items in exactly the same positions. Thus, “sets” and “lists” represent different concepts: A list is always ordered and a set has no repeated elements . Example 1 (Using the terminology) People, in their everyday lives, deal with the issues of “order is important” and “order is not important.” Imagine that Tim, Jane, and Linda are going to go shopping for groceries. Tim makes a note to remind himself to get apples and bananas. Tim’s note might be written out in an orderly manner, or might just be words randomly placed on a sheet of paper. In any case, the purpose of the note is to remind him to buy some apples and bananas and, we assume, the order in which these items are noted is not important. The number of apples and bananas is not specified in the note. That will be determined at the store after inspecting the quality of the apples and bananas. The best model for this note is a set. Tim might have written c circlecopyrt Edward A. Bender & S. Gill Williamson 2005. All rights reserved. Basic Counting and Listing { apples, bananas } . We have added the braces to emphasize that we are talking about sets. Suppose Jane wrote { bananas, apples } and Linda wrote { apples, bananas, apples } . Linda was a bit forgetful and wrote apples twice. It doesn’t matter. All three sets are the same and all call for the purchase of some apples and some bananas. If Linda’s friend Mary had made the note { peaches, bananas, oranges } and Linda and Mary had decided to combine their notes and go shopping together, they would have gone to the store to get...
View
Full
Document
This note was uploaded on 02/11/2008 for the course CSE 21 taught by Professor Graham during the Fall '07 term at UCSD.
 Fall '07
 Graham
 The Land

Click to edit the document details