CS112 Fundamentals of
Programming Abstractions
Sets
Yinglin WANG
CS Dept., SJTU
CS112 Fundamentals of
Programming Abstractions
Sets
When we want to
represent a collection of
elements where the order
is not important, the
collection is what
mathematicians would
call a set.
Saying that the order is
not important means that
we won’
t be asking
questions like "
what is
the second element
?"
Instead, we will just be
asking whether a given
value is a member of the
set.
We can specify a set by
listing its members or by
stating a rule that
identifies the members.
Small even numbers: {2, 4, 6, 8}
Single digit primes: {2, 3, 5, 7}
Strange numbers: {11, 17, 31, 53, 79}
Primary colors: {red, green, blue}
Small even numbers: {x | x is even and x < 10}
A set is an unordered collection of distinct elements.

This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*