Comp 283, 2025 Summer Session 1

Course Site for Comp 283

Learning Objectives

To learn the language of sets and tuples:

Sets - Definitions

A set is an unordered collection of objects.

The following are sets:

{\(1,2,3\)}

“all multiples of 7’’

{apples, \(7\), \(\texttt{True}\)}

Sets don’t inherently have an order.

Sets - Terminology

A set is a finite set if it has a finite number of elements.

Any set that is not finite is an infinite set.

Let \(A\) be a finite set. The number of different elements in \(A\) is called its cardinality.

The cardinality of a finite set is denoted \(\vert A \vert\) .

\(\{1,2,3\}\) is a finite set. Its cardinality is \(3\).

“all multiples of 7” is an infinite set. Cardinality here is a little more complicated… We will get back to that!

Sets - Notation

Elements

\(a \in A\) means \(a\) is an element of \(A\).

\(a \notin A\) means \(a\) is not an element of \(A\).

Example

Let \(A = \{\)“apples”, “bananas”, “oranges”\(\}\)

“apples” \(\in A\)

“blueberries” \(\notin A\)

Brackets and Parentheses

\([a,b]\) is the set of whole numbers \(\geq a\) and \(\leq b\).

\((a,b)\) is the set of whole numbers \(> a\) and \(< b\).

Examples

\[[1,5] = \{1,2,3,4,5\}\]
\[(1,5) = \{2,3,4\}\]
\[[1,5) = \{1,2,3,4\}\]

Set Notation

Sets are commonly expressed using set notation.

Within braces, we can write a rule consisting of a function, a vertical bar, and a set to which the function is applied.

Example

We can express the set \(\{\frac{1}{2}, \frac{1}{4}, \frac{1}{8} \}\) as…

Subsets

\(A\) is a subset of \(B\) if and only if every element of \(A\) is an element of \(B\).

Can also be written: \(A \subseteq B\)

Examples

Let \(A = \{1,3,5\}\) and \(B = \{1,2,3,4,5\}\).

\(A \subseteq B\).

Let \(A = \{1,2,3\}\) and \(B = \{3,2,1\}\).

\(A \subseteq B\) and \(B \subseteq A\).

Equality

\(A = B\) if and only if every element of \(A\) is an element of \(B\) and conversely every element of \(B\) is an element of \(A\). That is, \(A \subseteq B\) and \(B \subseteq A\).

Example

Let \(A = \{1,2,3\}\) and \(B = \{3,2,1\}\).

\(A \subseteq B\) and \(B \subseteq A\), so \(A=B\)

Intersection

\(A \cap B\) is the set of elements that are both in \(A\) and in \(B\).

Example

\(A = \{\)Apples, Bananas\(\}\)
\(B= \{\)Bananas, Oranges\(\}\)
\(A \cap B =\) {Bananas}

Union

\(A \cup B\) is the set of elements that are in either \(A\) or \(B\).

Example

\(A = \{\)Apples, Bananas\(\}\)
\(B= \{\)Bananas, Oranges\(\}\)
\(A \cup B =\) {Apples, Bananas, Oranges}

Common Sets

Tuples

A \(k\)-tuple is an ordered sequence of \(k\) elements, which we write down in parentheses, \((a_1,a_2,\ldots,a_k)\).

The most common tuple seen in math is the coordinate pair \((x,y)\) on a graph.

A 2-tuple is commonly called an ordered pair.

Two tuples are equal if and only if all of their corresponding elements are equal. \((a_1,a_2,\ldots,a_k)\) iff for all \(i\in[1,\ldots,k]\) we have \(a_i=b_i\).

Tuples - Cartesian Product

The basic operation to create tuples is the Cartesian Product of two sets.

The \textbf{cartesian product} of \(A\) and \(B\), \(A \times B = \{(a,b)\vert\) for all \(a \in A\) and for all \(b \in B\}\)

Example

Let \(L=\{a,b,c\}\) and let \(D = \{0,1\}\) \(L \times D = \{(a,0),(a,1),(b,0),(b,1),(c,0),(c,1)\}\) \(D \times L = \{(0,a),(0,b),(0,c),(1,a),(1, b),(1,c)\}\) \(L \times L = L^2 = \{(a,a),(a,b),(a,c),(b,a),(b, b),(b,c),(c,a),(c, b),(c,c)\}\)

The cartesian product is associative: \(D \times(L \times D) = (D \times L) \times D\).

The cartesian product is not necessarily commutative: \(D\times L \neq L \times D\).

Sequences, Strings, and Series

Some other structures we may use:

Concatenation

Concatenation is used to join two strings or lists by putting all elements of the second string behind all elements of the first.

Example

The concatenation of “hello” and “world” is “helloworld”.

Series

A series is a sum of a sequence of numbers, replacing commas by plus signs.

Any finite sequence, such as (\(x_1, x_2,\ldots, x_n\)), has a series \(x_1 + x_2 +\ldots+ x_n\) with a well-defined value.

This can also be written with summation notation: \(\sum_{i\in[1,n]}x_i\).

Counting Elements in Sets

The Sum rule states: Suppose that each element of a set has an assigned type. Then the total number of elements is the sum of the numbers of elements of each type.

The Product rule states: Suppose that elements of a set have features that can be chosen independently. Then the number of elements is the product of the numbers of choices.

The best way to demonstrate what this means is by example…

Counting Example 1

Counting Example 2

Permutations

The permutations of \(n\) distinct items are the set of all \(n\)-tuples that never repeat any item.

Example

Let \(A = \{Bob, Alice, Chris\}\)
All permutations of \(A\):
\(\big\{\{Bob, Alice, Chris\}, \{Bob, Chris, Alice\},\)
\(\{Alice, Chris, Bob\}, \{Alice, Bob, Chris\},\)
\(\{Chris, Bob, Alice\}, \{Chris, Alice, Bob\}\big\}\)

Counting Permutations

The number of permutations of \(n\) items is \(n!\) (\(n\) factorial).

As a reminder, \(n! = n \cdot (n-1) \cdot (n-2) \cdot \ldots \cdot 1\).

Example

Let \(A = \{Bob, Alice, Chris\}\)
The number of possible permutations of \(A\) is \(3! = 3 \cdot 2 \cdot 1 = 6\).

Permutations Examples

Let’s go back to our previous example.

Example Expanded

Combinations

A \(k\)-combination is a set with \(k\) elements chosen from a set of \(n\) possible items with no repeats.

(Since these are sets, order does not matter!)

Example

Compute all \(2\)-combinations of \(\{a,b,c\}\).
\(\{a,b\},\{a,c\}, \{b,c\}\)

Permutations vs. Combinations

The \(2\)-permutations of \(\{a,b,c\}\) would be \((a,b), (b,a), (a,c), (c,a), (b,c), (c,b)\).

Number of Combinations

The number of \(k\)-combinations of a set of size \(n\) is \({n \choose k}\), read as “\(n\) choose \(k\)”.

Other ways you may see “\(n\) choose \(k\)” written:

How to Compute n choose k

\[{n \choose k} = \frac{n!}{k!(n-k)!}\]

Why does this formula work? Some reasoning behind this by example…

Example

Example Generalized…