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.