Let’s get started

We want you to be successful.

We will work together to build an environment in CSE 20 that supports your learning in a way that respects your perspectives, experiences, and identities (including race, ethnicity, heritage, gender, sex, class, sexuality, religion, ability, age, educational background, etc.). Our goal is for you to engage with interesting and challenging concepts and feel comfortable exploring, asking questions, and thriving.

If you or someone you know is suffering from food and/or housing insecurities there are UCSD resources here to help:

Basic Needs Office: https://basicneeds.ucsd.edu/

Triton Food Pantry (in the old Student Center) is free and anonymous, and includes produce:

https://www.facebook.com/tritonfoodpantry/

Mutual Aid UCSD: https://mutualaiducsd.wordpress.com/

Financial aid resources, the possibility of emergency grant funding, and off-campus housing referral resources are available: see your College Dean of Student Affairs.

If you find yourself in an uncomfortable situation, ask for help. We are committed to upholding University policies regarding nondiscrimination, sexual violence and sexual harassment. Here are some campus contacts that could provide this help: Counseling and Psychological Services (CAPS) at 858 534-3755 or http://caps.ucsd.edu; OPHD at 858 534-8298 or ophd@ucsd.edu , http://ophd.ucsd.edu; CARE at Sexual Assault Resource Center at 858 534-5793 or sarc@ucsd.edu , http://care.ucsd.edu.

Please reach out (minnes@ucsd.edu) if you need support with extenuating circumstances affecting CSE 20.

Welcome to CSE 20: Discrete Math for CS in Winter 2026!

Class website: https://canvas.ucsd.edu/

Instructor: Prof. Mia Minnes "Minnes" rhymes with Guinness, minnes@ucsd.edu, http://cseweb.ucsd.edu/ minnes

Our team: One instructor + two TAs and four tutors + all of you

Fill in contact info for students around you, if you’d like:

On a typical week in CSE 20: MWF Lectures (sometimes with pre-class reading), W Discussion, Review quiz, then T Homework due. Office hours (hosted by instructors and TAs and tutors) where you can come to talk about course concepts and ask for help as you work through sample problems and Q+A on Piazza available throughout the week. CSE 20 has one project and two tests this quarter. Demonstration of class website on Canvas (https://canvas.ucsd.edu/):

  1. Syllabus

  2. Notes for class + annotations

  3. Assignments (PDF, tex, solutions)

  4. Gradescope

  5. Piazza

  6. Dates

Pro-tip: you can use MATH109 to replace CSE20 for prerequisites and other requirements.

Themes and applications for CSE 20

Applications: Numbers (how to represent them and use them in Computer Science), Recommendation systems and their roots in machine learning (with applications like Netflix), “Under the hood" of computers (circuits, pixel color representation, data structures), Codes and information (secret message sharing and error correction), Bioinformatics algorithms and genomics (DNA and RNA).

Week 1 at a glance

We will be learning and practicing to:

TODO:

#FinAid Assignment on Canvas (complete as soon as possible)

Review quiz based on class material each day (due Friday April 5, 2024)

Homework assignment 1 (due Tuesday April 9, 2024).

Week 1 Monday: Modeling applications

What data should we encode about each Netflix account holder to help us make effective recommendations?

In machine learning, clustering can be used to group similar data for prediction and recommendation. For example, each Netflix user’s viewing history can be represented as a \(n\)-tuple indicating their preferences about movies in the database, where \(n\) is the number of movies in the database. People with similar tastes in movies can then be clustered to provide recommendations of movies for one another. Mathematically, clustering is based on a notion of distance between pairs of \(n\)-tuples.

Data Types: sets, \(n\)-tuples, and strings

Term Examples:
(add additional examples from class)
set
unordered collection of elements
\(7 \in \{43, 7, 9 \}\) \(2 \notin \{43, 7, 9 \}\)
repetition doesn’t matter
Equal sets agree on membership of all elements
\(n\)-tuple
ordered sequence of elements with \(n\) “slots" (\(n >0\))
repetition matters, fixed length
Equal \(n\)-tuples have corresponding components equal
string
ordered finite sequence of elements each from specified set (called the alphabet over which the string is defined)
repetition matters, arbitrary finite length
Equal strings have same length and corresponding characters equal

Special cases:

When \(n=2\), the 2-tuple is called an ordered pair.

A string of length \(0\) is called the empty string and is denoted \(\lambda\).

A set with no elements is called the empty set and is denoted \(\{\}\) or \(\emptyset\).

In the table below, each row represents a user’s ratings of movies:  (check) indicates the person liked the movie,  (x) that they didn’t, and \(\bullet\) (dot) that they didn’t rate it one way or another (neutral rating or didn’t watch). Can encode these ratings numerically with \(1\) for  (check), \(-1\) for  (x), and \(0\) for \(\bullet\) (dot).

Person Superman Wicked KPop Demon Hunters A Minecraft Movie Ratings written as a \(4\)-tuple
\(P_1\) \(\bullet\)
\(P_2\)
\(P_3\)
\(P_4\) \(\bullet\)
\(You\)

Conclusion: Modeling involves choosing data types to represent and organize data

Week 1 Wednesday: Defining sets

Notation and prerequisites

Term Notation Example(s) We say in English …
all reals \(\mathbb{R}\) The (set of all) real numbers (numbers on the number line)
all integers \(\mathbb{Z}\) The (set of all) integers (whole numbers including negatives, zero, and positives)
all positive integers \(\mathbb{Z}^+\) The (set of all) strictly positive integers
all natural numbers \(\mathbb{N}\) The (set of all) natural numbers. Note: we use the convention that \(0\) is a natural number.

To define sets:

To define a set using roster method, explicitly list its elements. That is, start with \(\{\) then list elements of the set separated by commas and close with \(\}\).

To define a set using set builder definition, either form “The set of all \(x\) from the universe \(U\) such that \(x\) is ..." by writing \[\{x \in U \mid ...x... \}\] or form “the collection of all outputs of some operation when the input ranges over the universe \(U\)" by writing \[\{ ...x... \mid x\in U \}\]

We use the symbol \(\in\) as “is an element of” to indicate membership in a set.

Example sets: For each of the following, identify whether it’s defined using the roster method or set builder notation and give an example element.

Can we infer the data type of the example element from the notation?

RNA is made up of strands of four different bases that encode genomic information in specific ways.
The bases are elements of the set \(B = \{\texttt{A}, \texttt{C}, \texttt{U}, \texttt{G}\}\). Strands are ordered nonempty finite sequences of bases.

Formally, to define the set of all RNA strands, we need more than roster method or set builder descriptions.

New! Recursive Definitions of Sets: The set \(S\) (pick a name) is defined by: \[\begin{array}{ll} \textrm{Basis Step: } & \textrm{Specify finitely many elements of } S\\ \textrm{Recursive Step: } & \textrm{Give rule(s) for creating a new element of } S \textrm{ from known values existing in } S, \\ & \textrm{and potentially other values}. \\ \end{array}\] The set \(S\) then consists of all and only elements that are put in \(S\) by finitely many (a nonnegative integer number) of applications of the recursive step after the basis step.

Definition The set of nonnegative integers \(\mathbb{N}\) is defined (recursively) by: \[\begin{array}{ll} \textrm{Basis Step: } & \phantom{0 \in \mathbb{N}} \\ \textrm{Recursive Step: } & \phantom{\textrm{If } n \in \mathbb{N} \textrm{, then } n+1 \in \mathbb{N}} \end{array}\]

Examples:

Definition The set of all integers \(\mathbb{Z}\) is defined (recursively) by: \[\begin{array}{ll} \textrm{Basis Step: } & \phantom{0 \in \mathbb{Z}} \\ \textrm{Recursive Step: } & \phantom{\textrm{If } x \in \mathbb{Z} \textrm{, then } x+1 \in \mathbb{Z} \textrm{ and } x-1 \in \mathbb{Z}} \end{array}\]

Examples:

Definition The set of RNA strands \(S\) is defined (recursively) by: \[\begin{array}{ll} \textrm{Basis Step: } & \texttt{A}\in S, \texttt{C}\in S, \texttt{U}\in S, \texttt{G}\in S \\ \textrm{Recursive Step: } & \textrm{If } s \in S\textrm{ and }b \in B \textrm{, then }sb \in S \end{array}\] where \(sb\) is string concatenation.

Examples:

Definition The set of bitstrings (strings of 0s and 1s) is defined (recursively) by: \[\begin{array}{ll} \textrm{Basis Step: } & \phantom{\lambda \in X} \\ \textrm{Recursive Step: } & \phantom{\textrm{If } s \in X \textrm{, then } s0 \in X \text{ and } s1 \in X} \end{array}\]

Notation: We call the set of bitstrings \(\{0,1\}^*\) and we say this is the set of all strings over \(\{0,1\}\).

Examples:

Pro-tip: the meaning of writing one element next to another like \(xy\) depends on the data-types of \(x\) and \(y\). When \(x\) and \(y\) are strings, the convention is that \(xy\) is the result of string concatenation. When \(x\) and \(y\) are numbers, the convention is that \(xy\) is the result of multiplication. This is (one of the many reasons) why is it very important to declare the data-type of variables before we use them.

Fill in the missing entries in the table:

Set Example elements in this set and their data type:
\(B\) ACGU
\((\texttt{A}, \texttt{C})\) \((\texttt{U}, \texttt{U})\)
\(B \times \{-1,0,1\}\)
\(\{-1,0,1\} \times B\)
\((0,0,0)\)
\(\{\texttt{A}, \texttt{C}, \texttt{G}, \texttt{U}\} \circ \{\texttt{A}, \texttt{C}, \texttt{G}, \texttt{U}\}\)
\(\texttt{G}\texttt{G}\texttt{G}\texttt{G}\)

Week 1 Friday: Defining functions

Term Notation Example(s) We say in English …
sequence \(x_1, \ldots, x_n\) A sequence \(x_1\) to \(x_n\)
summation \(\sum_{i=1}^n x_i\) or \(\displaystyle{\sum_{i=1}^n x_i}\) The sum of the terms of the sequence \(x_1\) to \(x_n\)
piecewise rule definition \(f(x) = \begin{cases} \text{rule 1 for } x & \text{when~COND 1} \\ \text{rule 2 for } x & \text{when COND 2}\end{cases}\) Define \(f\) of \(x\) to be the result of applying rule 1 to \(x\) when condition COND 1 is true and the result of applying rule 2 to \(x\) when condition COND 2 is true. This can be generalized to having more than two conditions (or cases).
function application \(f(7)\) \(f\) of \(7\) or \(f\) applied to \(7\) or the image of \(7\) under \(f\)
\(f(z)\) \(f\) of \(z\) or \(f\) applied to \(z\) or the image of \(z\) under \(f\)
\(f(g(z))\) \(f\) of \(g\) of \(z\) or \(f\) applied to the result of \(g\) applied to \(z\)
absolute value \(\lvert -3 \rvert\) The absolute value of \(-3\)
square root \(\sqrt{9}\) The non-negative square root of \(9\)

Pro-tip: the meaning of two vertical lines \(| ~~~ |\) depends on the data-types of what’s between the lines. For example, when placed around a number, the two vertical lines represent absolute value. We’ve seen a single vertial line \(|\) used as part of set builder definitions to represent “such that”. Again, this is (one of the many reasons) why is it very important to declare the data-type of variables before we use them.

Example: The absolute value function

Domain

Codomain

Rule

Recall our representation of Netflix users’ ratings of movies as \(n\)-tuples, where \(n\) is the number of movies in the database. Each component of the \(n\)-tuple is \(-1\) (didn’t like the movie), \(0\) (neutral rating or didn’t watch the movie), or \(1\) (liked the movie).

Consider the ratings \(P_1 = (-1, 0, 1, 0)\), \(P_2 = (1, 1, -1, 0)\), \(P_3 = (1, 1, 1, 0)\), \(P_4 = (0,-1,1, 0)\)

Which of \(P_1\), \(P_2\), \(P_3\) has movie preferences most similar to \(P_4\)?

One approach to answer this question: use functions to quantify difference among user preferences.

For example, consider the function \(d_0: \{-1,0,1\}^4 \times \{-1,0,1\}^4 \to \mathbb{R}\) given by \[d_0 (~(~ (x_1, x_2, x_3, x_4), (y_1, y_2, y_3, y_4) ~) ~) = \sqrt{ (x_1 - y_1)^2 + (x_2 - y_2)^2 + (x_3 -y_3)^2 + (x_4 -y_4)^2}\]

When the domain of a function is a recursively defined set, the rule assigning images to domain elements (outputs) can also be defined recursively.

Recall: The set of RNA strands \(S\) is defined (recursively) by: \[\begin{array}{ll} \textrm{Basis Step: } & \texttt{A}\in S, \texttt{C}\in S, \texttt{U}\in S, \texttt{G}\in S \\ \textrm{Recursive Step: } & \textrm{If } s \in S\textrm{ and }b \in B \textrm{, then }sb \in S \end{array}\] where \(sb\) is string concatenation.

Definition (Of a function, recursively) A function rnalen that computes the length of RNA strands in \(S\) is defined by: \[\begin{array}{llll} & & \textit{rnalen} : S & \to \mathbb{Z}^+ \\ \textrm{Basis Step:} & \textrm{If } b \in B\textrm{ then } & \textit{rnalen}(b) & = 1 \\ \textrm{Recursive Step:} & \textrm{If } s \in S\textrm{ and }b \in B\textrm{, then } & \textit{rnalen}(sb) & = 1 + \textit{rnalen}(s) \end{array}\]

The domain of rnalen is
The codomain of rnalen is
Example function application: \[rnalen(\texttt{A}\texttt{C}\texttt{U}) = \phantom{1+ rnalen(\texttt{A}\texttt{C}) = 1 + (1 + rnalen(\texttt{A}) ) = 1 + ( 1 + 1) = 3}\]

Example: A function basecount that computes the number of a given base \(b\) appearing in a RNA strand \(s\) is defined recursively:

\[\begin{array}{llll} & & \textit{basecount} : S \times B & \to \mathbb{N} \\ \textrm{Basis Step:} & \textrm{If } b_1 \in B, b_2 \in B & \textit{basecount}(~(b_1, b_2)~) & = \begin{cases} 1 & \textrm{when } b_1 = b_2 \\ 0 & \textrm{when } b_1 \neq b_2 \\ \end{cases} \\ \textrm{Recursive Step:} & \textrm{If } s \in S, b_1 \in B, b_2 \in B &\textit{basecount}(~(s b_1, b_2)~) & = \begin{cases} 1 + \textit{basecount}(~(s, b_2)~) & \textrm{when } b_1 = b_2 \\ \textit{basecount}(~(s, b_2)~) & \textrm{when } b_1 \neq b_2 \\ \end{cases} \end{array}\]

Review Quiz

The review quiz is available on PrairieLearn at https://us.prairielearn.com/pl/ and covers